-
Notifications
You must be signed in to change notification settings - Fork 4
240924 문환희 all_part_1,2,3 풀이 #65
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
0b55223
e8cde25
f5457e8
61a3005
c02944c
03a6976
f95b71e
6914fd2
2e7d63a
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,23 @@ | ||
| import java.util.HashSet; | ||
| import java.util.Scanner; | ||
|
|
||
| public class 가희와_키워드 { | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner sc = new Scanner(System.in); | ||
| int n = sc.nextInt(); | ||
| int m = sc.nextInt(); | ||
| sc.nextLine(); | ||
| HashSet<String> set = new HashSet<>(); | ||
| for(int i = 0; i < n; i++) { | ||
| set.add(sc.nextLine()); | ||
| } | ||
| for(int i = 0; i < m; i++) { | ||
| String[] input = sc.nextLine().split(","); | ||
| for(String s : input) { | ||
| set.remove(s); | ||
| } | ||
| System.out.println(set.size()); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import java.util.*; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class 등수_구하기 { | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| StringTokenizer st = new StringTokenizer(scanner.nextLine()); | ||
|
|
||
| int n = Integer.parseInt(st.nextToken()); | ||
| int s = Integer.parseInt(st.nextToken()); | ||
| int p = Integer.parseInt(st.nextToken()); | ||
|
|
||
| int[] scores; | ||
| if (n > 0) { | ||
| scores = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray(); | ||
| } else { | ||
|
Comment on lines
+16
to
+17
Owner
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. 이제 정말 stream잘쓰시는 군요! |
||
| scores = new int[0]; | ||
| } | ||
|
|
||
| if (n == 0) { | ||
| System.out.println(1); | ||
| return; | ||
| } | ||
| int rank = 1; | ||
|
|
||
| if(n == p && scores[n - 1] >= s) { | ||
| System.out.println(-1); | ||
| return; | ||
| } | ||
|
|
||
| for(int i = 0; i < n; i++) { | ||
| if(scores[i] > s) { | ||
| rank++; | ||
| } | ||
| else { | ||
| break; | ||
| } | ||
| } | ||
| System.out.println(rank); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
|
|
||
| public class 진우와_달여행 { | ||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
|
||
| String[] input = br.readLine().split(" "); | ||
| int n = Integer.parseInt(input[0]); | ||
| int m = Integer.parseInt(input[1]); | ||
|
|
||
| int[][] map = new int[n][m]; | ||
| int[][][] dp = new int[n][m][3]; | ||
| int[][] ways = {{-1, -1}, {-1, 0}, {-1, +1}}; | ||
|
|
||
|
|
||
| for(int i = 0; i < n; i++){ | ||
| map[i] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); | ||
| } | ||
|
|
||
| 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++) { | ||
|
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. 3중 for문을 사용하셨네요!! |
||
| for (int j = 0; j < m; j++) { | ||
| for (int k = 0; k < 3; k++) { | ||
| int prevJ = j + ways[k][1]; | ||
| if (prevJ >= 0 && prevJ < m) { | ||
| dp[i][j][k] = map[i][j] + Math.min(dp[i - 1][prevJ][(k + 1) % 3], dp[i - 1][prevJ][(k + 2) % 3]); | ||
| } else { | ||
| dp[i][j][k] = Integer.MAX_VALUE; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| int minFuel = Integer.MAX_VALUE; | ||
| for (int j = 0; j < m; j++) { | ||
| for (int k = 0; k < 3; k++) { | ||
| minFuel = Math.min(minFuel, dp[n - 1][j][k]); | ||
| } | ||
| } | ||
|
|
||
| System.out.println(minFuel); | ||
|
|
||
|
|
||
| br.close(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import java.io.*; | ||
|
|
||
| public class 전구와_스위치 { | ||
|
|
||
| public static void toggle(int[] arr, int idx) { | ||
| arr[idx] ^= 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. 저 개인적으로 ^ 이거 정말 잘 안써서 되게 신기했습니다 |
||
| if (idx > 0) arr[idx - 1] ^= 1; | ||
| if (idx < arr.length - 1) arr[idx + 1] ^= 1; | ||
| } | ||
|
|
||
| public static int solve(int[] now, int[] goal, int n, boolean pressFirst) { | ||
| int[] bulbs = now.clone(); | ||
| int pressCount = 0; | ||
|
|
||
| if (pressFirst) { | ||
| toggle(bulbs, 0); | ||
| pressCount++; | ||
| } | ||
|
|
||
| for (int i = 1; i < n; i++) { | ||
| if (bulbs[i - 1] != goal[i - 1]) { | ||
| toggle(bulbs, i); | ||
| pressCount++; | ||
| } | ||
| } | ||
|
|
||
| if (bulbs[n - 1] != goal[n - 1]) { | ||
| return Integer.MAX_VALUE; | ||
| } | ||
|
|
||
| return pressCount; | ||
| } | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| int n = Integer.parseInt(br.readLine()); | ||
| int[] now = new int[n]; | ||
| int[] goal = new int[n]; | ||
|
|
||
| String nowString = br.readLine(); | ||
| String goalString = br.readLine(); | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| now[i] = nowString.charAt(i) - '0'; | ||
| goal[i] = goalString.charAt(i) - '0'; | ||
| } | ||
|
|
||
| int resultWithoutFirst = solve(now, goal, n, false); | ||
| int resultWithFirst = solve(now, goal, n, true); | ||
|
|
||
| int answer = Math.min(resultWithoutFirst, resultWithFirst); | ||
| if (answer == Integer.MAX_VALUE) { | ||
| System.out.println(-1); | ||
| } else { | ||
| System.out.println(answer); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 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)); | ||
| int n = Integer.parseInt(br.readLine()); | ||
| int[][] map = new int[n][n]; | ||
| long[][] dp = new long[n][n]; | ||
|
|
||
| for (int i = 0; i < n; i++) { | ||
| map[i] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); | ||
| } | ||
|
|
||
| dp[0][0] = 1; | ||
|
|
||
| for(int i = 0; i < n; i++) { | ||
| for(int j = 0; j < n; j++) { | ||
| if(dp[i][j] >= 1 && map[i][j] != 0) { | ||
|
|
||
| if(j + map[i][j] < n) { | ||
| dp[i][j + map[i][j]] += dp[i][j]; | ||
| } | ||
| if(i + map[i][j] < n) { | ||
| dp[i + map[i][j]][j] += dp[i][j]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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,69 @@ | ||
| import java.io.*; | ||
| import java.util.Deque; | ||
| import java.util.HashSet; | ||
| import java.util.LinkedList; | ||
| import java.util.Set; | ||
|
|
||
| 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]; | ||
| int[] counts = new int[d + 1]; | ||
|
|
||
|
|
||
| for(int i = 0; i < n; i++) { | ||
| belt[i] = Integer.parseInt(br.readLine()); | ||
| } | ||
| int answer = 0; | ||
| Deque<Integer> window = new LinkedList<>(); | ||
|
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. ArrayDeque을 사용하는 게 더 좋다고 하더라구요 with 남노씨 |
||
|
|
||
| int current = 0; | ||
|
|
||
|
|
||
| for (int i = 0; i < k; i++) { | ||
| int sushi = belt[i]; | ||
| window.addLast(sushi); | ||
| if (counts[sushi] == 0) { | ||
| current++; | ||
| } | ||
| counts[sushi]++; | ||
| } | ||
| answer = counts[c] == 0 ? current + 1 : current; | ||
|
|
||
| for(int i = 1; i < n; i++) { | ||
|
|
||
| int removed = window.removeFirst(); | ||
| counts[removed]--; | ||
| if(counts[removed] == 0) { | ||
| current--; | ||
| } | ||
|
|
||
| int addNew = belt[(i + k - 1) % n]; | ||
| window.addLast(addNew); | ||
| if(counts[addNew] == 0) { | ||
| current++; | ||
| } | ||
|
|
||
| counts[addNew]++; | ||
|
|
||
| int res = counts[c] == 0 ? current + 1 : current; | ||
| answer = Math.max(answer, res); | ||
|
|
||
| } | ||
|
|
||
| bw.write(answer + "\n"); | ||
|
|
||
| bw.flush(); | ||
| bw.close(); | ||
| br.close(); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 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 answer = 0; | ||
|
|
||
| Deque<Integer> dq = new ArrayDeque<Integer>(); | ||
|
|
||
| int n = Integer.parseInt(br.readLine()); | ||
| int m = Integer.parseInt(br.readLine()); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| for (int i = 0; i < m; i++) { | ||
| dq.addLast(Integer.parseInt(st.nextToken())); | ||
| } | ||
| int[] arr = dq.stream().mapToInt(Integer::intValue).toArray(); | ||
| int gap = 0; | ||
|
|
||
| for (int i = 1; i < arr.length; i++) { | ||
| gap = Math.max(gap, arr[i] - arr[i - 1]); | ||
| } | ||
|
|
||
| answer = Math.max(Math.max((gap + 1) / 2, arr[0]), n - arr[arr.length - 1]); | ||
|
|
||
| System.out.println(answer); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import java.io.*; | ||
| import java.util.Arrays; | ||
| import java.util.PriorityQueue; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| public class 카드합체놀이 { | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| String[] input = br.readLine().split(" "); | ||
| int n = Integer.parseInt(input[0]); | ||
| int m = Integer.parseInt(input[1]); | ||
| PriorityQueue<Long> pq = new PriorityQueue<>(); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
| for(int i = 0; i < n; i++) { | ||
| pq.add(Long.parseLong(st.nextToken())); | ||
| } | ||
|
|
||
| for(int i = 0; i < m; i++) { | ||
| long p = pq.poll(); | ||
| long q = pq.poll(); | ||
| for(int j = 0; j < 2; j++) { | ||
| pq.add(p + q); | ||
| } | ||
|
Comment on lines
+22
to
+24
Owner
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. 두번 넣어주는거 for문 사용하셨군요! ㅋㅋ |
||
| } | ||
|
|
||
| long answer = 0; | ||
| for(long i : pq) { | ||
| answer += i; | ||
| } | ||
|
|
||
|
|
||
| System.out.println(answer); | ||
| } | ||
| } | ||
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.
점점 BufferedReader는 잊혀져가는 게 넘 웃깁니다