-
Notifications
You must be signed in to change notification settings - Fork 4
240924 주정윤 all_part_1, 2, 3 풀이 #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
db8ef68
a964a2d
3fdf2fe
451229e
90a8ef6
27d76c9
2e89184
551f1ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class 가희와 키워드 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
|
|
||
| String[] input = br.readLine().split(" "); | ||
| int n = Integer.parseInt(input[0]); | ||
| int m = Integer.parseInt(input[1]); | ||
|
|
||
| HashSet<String> memo = new HashSet<>(); | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| memo.add(br.readLine()); | ||
| } | ||
|
|
||
| for (int i = 0; i < m; i++) { | ||
| String[] words = br.readLine().split(","); | ||
| for (String word : words) { | ||
| memo.remove(word); | ||
| } | ||
| bw.write(memo.size() + "\n"); | ||
| } | ||
|
|
||
| bw.flush(); | ||
| bw.close(); | ||
| br.close(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class 등수 구하기 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| int n = Integer.parseInt(st.nextToken()); | ||
| int newScore = Integer.parseInt(st.nextToken()); | ||
| int p = Integer.parseInt(st.nextToken()); | ||
|
|
||
| int[] scores = new int[n]; | ||
| if (n > 0) { | ||
| st = new StringTokenizer(br.readLine()); | ||
| for (int i = 0; i < n; i++) { | ||
| scores[i] = Integer.parseInt(st.nextToken()); | ||
| } | ||
| } | ||
|
|
||
| if (n == 0) { | ||
| System.out.println(1); | ||
| return; | ||
| } | ||
|
|
||
| if (n == p && newScore <= scores[n - 1]) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저랑 풀이가 비슷하신 것 같아요! |
||
| System.out.println(-1); | ||
| return; | ||
| } | ||
|
|
||
| int rank = 1; | ||
| for (int i = 0; i < n; i++) { | ||
| if (newScore < scores[i]) { | ||
| rank++; | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
|
Comment on lines
+32
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 로직은 저랑 똑같네요 |
||
|
|
||
| System.out.println(rank); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class 진우와 달여행 { | ||
| static int[][] map; | ||
| static int[][][] dp; | ||
| static int n, m; | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| n = Integer.parseInt(st.nextToken()); | ||
| m = Integer.parseInt(st.nextToken()); | ||
|
|
||
| map = new int[n][m]; | ||
| dp = new int[n][m][3]; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| st = new StringTokenizer(br.readLine()); | ||
| for (int j = 0; j < m; j++) { | ||
| map[i][j] = Integer.parseInt(st.nextToken()); | ||
| Arrays.fill(dp[i][j], Integer.MAX_VALUE); | ||
| } | ||
| } | ||
|
|
||
| for (int j = 0; j < m; j++) { | ||
| dp[0][j][0] = dp[0][j][1] = dp[0][j][2] = map[0][j]; | ||
| } | ||
|
|
||
| for (int i = 1; i < n; i++) { | ||
| for (int j = 0; j < m; j++) { | ||
| if (j > 0) { | ||
| dp[i][j][0] = Math.min(dp[i][j][0], dp[i - 1][j - 1][1] + map[i][j]); | ||
| } | ||
| dp[i][j][1] = Math.min(dp[i][j][1], dp[i - 1][j][0] + map[i][j]); | ||
| if (j < m - 1) { | ||
| dp[i][j][2] = Math.min(dp[i][j][2], dp[i - 1][j + 1][1] + map[i][j]); | ||
|
Comment on lines
+33
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 디피가 너무 어려워서 dfs로 풀었는데 디피 풀이 알아갑니다 ㅎㅎ |
||
| } | ||
| } | ||
| } | ||
|
|
||
| int minFuel = Integer.MAX_VALUE; | ||
| for (int j = 0; j < m; j++) { | ||
| minFuel = Math.min(minFuel, Math.min(dp[n - 1][j][0], Math.min(dp[n - 1][j][1], dp[n - 1][j][2]))); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 숫자 4개 비교 극한의 효율로 쓰셨네요 |
||
| } | ||
|
|
||
| System.out.println(minFuel); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import java.io.*; | ||
|
|
||
| public class 전구와 스위치 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
|
|
||
| int n = Integer.parseInt(br.readLine()); | ||
| char[] current = br.readLine().toCharArray(); | ||
| char[] target = br.readLine().toCharArray(); | ||
|
|
||
| int result1 = solve(current.clone(), target, n, false); | ||
| int result2 = solve(current.clone(), target, n, true); | ||
|
|
||
| int answer = Math.min(result1, result2); | ||
| if (answer == Integer.MAX_VALUE) { | ||
| bw.write("-1\n"); | ||
| } else { | ||
| bw.write(answer + "\n"); | ||
| } | ||
|
|
||
| bw.flush(); | ||
| bw.close(); | ||
| br.close(); | ||
| } | ||
|
|
||
| public static int solve(char[] current, char[] target, int n, boolean firstSwitch) { | ||
| int count = 0; | ||
| if (firstSwitch) { | ||
| switchLamp(current, 0); | ||
| count++; | ||
| } | ||
|
|
||
| for (int i = 1; i < n; i++) { | ||
| if (current[i - 1] != target[i - 1]) { | ||
| switchLamp(current, i); | ||
| count++; | ||
| } | ||
| } | ||
|
|
||
| if (current[n - 1] != target[n - 1]) { | ||
| return Integer.MAX_VALUE; | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
|
|
||
| public static void switchLamp(char[] current, int index) { | ||
| for (int i = index; i <= index + 1 && i < current.length; i++) { | ||
| current[i] = current[i] == '0' ? '1' : '0'; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import java.io.*; | ||
|
|
||
| public class 점프 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
|
|
||
| int n = Integer.parseInt(br.readLine()); | ||
| int[][] board = new int[n][n]; | ||
| long[][] dp = new long[n][n]; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| String[] line = br.readLine().split(" "); | ||
| for (int j = 0; j < n; j++) { | ||
| board[i][j] = Integer.parseInt(line[j]); | ||
| } | ||
| } | ||
|
|
||
| dp[0][0] = 1; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| for (int j = 0; j < n; j++) { | ||
| if (i == n - 1 && j == n - 1) { | ||
| break; | ||
| } | ||
| int jump = board[i][j]; | ||
| if (i + jump < n) { | ||
| dp[i + jump][j] += dp[i][j]; | ||
| } | ||
| if (j + jump < n) { | ||
| dp[i][j + jump] += dp[i][j]; | ||
| } | ||
|
Comment on lines
+26
to
+32
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 디피는 역시 비슷한 풀이가 많네요 |
||
| } | ||
| } | ||
|
|
||
| bw.write(dp[n - 1][n - 1] + "\n"); | ||
|
|
||
| bw.flush(); | ||
| bw.close(); | ||
| br.close(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import java.io.*; | ||
|
|
||
| public class 회전초밥 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
|
|
||
| String[] input = br.readLine().split(" "); | ||
| int n = Integer.parseInt(input[0]); | ||
| int d = Integer.parseInt(input[1]); | ||
| int k = Integer.parseInt(input[2]); | ||
| int c = Integer.parseInt(input[3]); | ||
|
|
||
| int[] belt = new int[n]; | ||
| for (int i = 0; i < n; i++) { | ||
| belt[i] = Integer.parseInt(br.readLine()); | ||
| } | ||
|
|
||
| int[] sushi = new int[d + 1]; | ||
| int uniqueCount = 0; | ||
| for (int i = 0; i < k; i++) { | ||
| if (sushi[belt[i]] == 0) uniqueCount++; | ||
| sushi[belt[i]]++; | ||
| } | ||
|
|
||
| int maxSushi = uniqueCount; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| int endIndex = (i + k) % n; | ||
|
|
||
| if (sushi[belt[i]] == 1) uniqueCount--; | ||
| sushi[belt[i]]--; | ||
|
|
||
| if (sushi[belt[endIndex]] == 0) uniqueCount++; | ||
| sushi[belt[endIndex]]++; | ||
|
|
||
| int currentMax = uniqueCount; | ||
| if (sushi[c] == 0) currentMax++; | ||
|
|
||
| maxSushi = Math.max(maxSushi, currentMax); | ||
| } | ||
|
|
||
| bw.write(maxSushi + "\n"); | ||
|
|
||
| bw.flush(); | ||
| bw.close(); | ||
| br.close(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class 어두운 굴다리 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
|
||
| int n = Integer.parseInt(br.readLine()); //터널 길이 | ||
| int m = Integer.parseInt(br.readLine()); //가로등 개수 | ||
| int[] lights = new int[m]; | ||
|
|
||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| for (int i = 0; i < m; i++) { | ||
| lights[i] = Integer.parseInt(st.nextToken()); | ||
| } | ||
|
|
||
| int maxDistance = Math.max(lights[0], n - lights[m - 1]); //끝에서의 거리 처리 | ||
|
|
||
| for (int i = 1; i < m; i++) { | ||
| int distance = (lights[i] - lights[i - 1] + 1) / 2; | ||
| maxDistance = Math.max(maxDistance, distance); | ||
| } | ||
|
Comment on lines
+18
to
+23
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드가 이렇게 짧을 수 있군요,, 배워갑니다 |
||
|
|
||
| System.out.println(maxDistance); | ||
| br.close(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import java.io.*; | ||
| import java.util.*; | ||
|
|
||
| public class 카드 합체 놀이 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| int n = Integer.parseInt(st.nextToken()); //카드의 개수 | ||
| int m = Integer.parseInt(st.nextToken()); //카드 합체 횟수 | ||
|
|
||
| PriorityQueue<Long> pq = new PriorityQueue<>(); | ||
|
|
||
| //카드 입력 받기 | ||
| st = new StringTokenizer(br.readLine()); | ||
| for (int i = 0; i < n; i++) { | ||
| pq.add((long) Integer.parseInt(st.nextToken())); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Long.parseLong 으로 하시면 더 깔끔 할것 같습니다. |
||
| } | ||
|
|
||
| //m번 합체 | ||
| for (int i = 0; i < m; i++) { | ||
| long a = pq.poll(); | ||
| long b = pq.poll(); | ||
| long sum = a + b; | ||
|
|
||
| //카드 한장 아니고 두장 추가 | ||
| pq.add(sum); | ||
| pq.add(sum); | ||
| } | ||
|
|
||
| //남은 카드들의 합 계산 | ||
| long total = 0; | ||
| while (!pq.isEmpty()) { | ||
| total += pq.poll(); | ||
| } | ||
|
|
||
| System.out.println(total); | ||
| br.close(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해쉬셋만 쓰면 되는 쉬운 문제였던 기억이 나네요..