From 1aa93c9660211aeac86d24f752c5a3555078ce65 Mon Sep 17 00:00:00 2001 From: Jewan Baek <116615068+jewan1120@users.noreply.github.com> Date: 2025年3月24日 12:01:55 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[CT]=20?= =?UTF-8?q?=EB=82=98=EB=AC=B4=EB=B0=95=EB=A9=B8=5F250324?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353円254円264円353円260円225円353円251円270円.java" | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 "CodeTree/2021-2022353円205円204円/JW_353円202円230円353円254円264円353円260円225円353円251円270円.java" diff --git "a/CodeTree/2021-2022353円205円204円/JW_353円202円230円353円254円264円353円260円225円353円251円270円.java" "b/CodeTree/2021-2022353円205円204円/JW_353円202円230円353円254円264円353円260円225円353円251円270円.java" new file mode 100644 index 00000000..b0f4f92c --- /dev/null +++ "b/CodeTree/2021-2022353円205円204円/JW_353円202円230円353円254円264円353円260円225円353円251円270円.java" @@ -0,0 +1,136 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.PriorityQueue; +import java.util.StringTokenizer; + +public class JW_나무박멸 { + + static int n, m, k, c; + static int[][] board, visited; + static int[] dy = { -1, 1, 0, 0, -1, -1, 1, 1 }, dx = { 0, 0, -1, 1, -1, 1, 1, -1 }; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + c = Integer.parseInt(st.nextToken()); + board = new int[n][n]; + visited = new int[n][n]; + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < n; j++) + board[i][j] = Integer.parseInt(st.nextToken()); + } + int total = 0; + while (m--> 0) { + grow(); + breed(); + int[] target = find(); + total += target[2]; + if (target[0] == -1 && target[1] == -1) + break; + kill(target); + heal(); + } + System.out.println(total); + } + + private static void heal() { + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (visited[i][j]> 0) + visited[i][j]--; + } + + private static void grow() { + int[][] dBoard = new int[n][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + if (board[i][j]> 0) { + for (int d = 0; d < 4; d++) { + int ny = i + dy[d], nx = j + dx[d]; + if (isValid(ny, nx) && board[ny][nx]> 0) + dBoard[i][j]++; + } + } + } + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + board[i][j] += dBoard[i][j]; + } + + private static void breed() { + Deque dq = new ArrayDeque(); + int[][] dBoard = new int[n][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) { + if (board[i][j]> 0) { + for (int d = 0; d < 4; d++) { + int ny = i + dy[d], nx = j + dx[d]; + if (isValid(ny, nx) && visited[ny][nx] == 0 && board[ny][nx] == 0) + dq.offer(new int[] { ny, nx }); + } + if (dq.isEmpty()) + continue; + int amount = board[i][j] / dq.size(); + while (!dq.isEmpty()) { + int[] pos = dq.poll(); + dBoard[pos[0]][pos[1]] += amount; + } + } + } + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + board[i][j] += dBoard[i][j]; + } + + private static int[] find() { + PriorityQueue pq = new PriorityQueue( + (o1, o2) -> o1[2] != o2[2] ? o2[2] - o1[2] : o1[0] != o2[0] ? o1[0] - o2[0] : o1[1] - o2[1]); + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (board[i][j]> 0) { + int sum = board[i][j]; + for (int d = 4; d < 8; d++) { + for (int l = 1; l <= k; l++) { + int ny = i + dy[d] * l, nx = j + dx[d] * l; + if (isValid(ny, nx) && board[ny][nx]> 0) + sum += board[ny][nx]; + else + break; + } + } + pq.offer(new int[] { i, j, sum }); + } + if (pq.isEmpty()) + return new int[] { -1, -1, 0 }; + return pq.poll(); + } + + private static void kill(int[] target) { + int y = target[0], x = target[1]; + board[y][x] = 0; + visited[y][x] = c + 1; + for (int d = 4; d < 8; d++) { + for (int l = 1; l <= k; l++) { + int ny = y + dy[d] * l, nx = x + dx[d] * l; + if (isValid(ny, nx)) { + visited[ny][nx] = c + 1; + if (board[ny][nx] <= 0) { + break; + } else { + board[ny][nx] = 0; + } + } + } + } + } + + private static boolean isValid(int y, int x) { + return 0 <= y && y < n && 0 <= x && x < n; + } +} From f9ab4675f8f440cf1ae4a8a8f320b752631360b0 Mon Sep 17 00:00:00 2001 From: Jewan Baek <116615068+jewan1120@users.noreply.github.com> Date: 2025年3月26日 15:33:03 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[BOJ]=201851?= =?UTF-8?q?3=20=EC=83=98=ED=84=B0=5F250326?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/15001-20000353円262円210円/JW_18513.java" | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "BOJ/15001-20000353円262円210円/JW_18513.java" diff --git "a/BOJ/15001-20000353円262円210円/JW_18513.java" "b/BOJ/15001-20000353円262円210円/JW_18513.java" new file mode 100644 index 00000000..eaf74e27 --- /dev/null +++ "b/BOJ/15001-20000353円262円210円/JW_18513.java" @@ -0,0 +1,56 @@ +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.HashSet; + +public class JW_18513 { + + public static void main(String[] args) throws Exception { + int n = read(), k = read(); + Deque dq = new ArrayDeque(); + HashSet hs = new HashSet(); + for (int i = 0; i < n; i++) { + int p = read(); + dq.offer(new int[] { p, p }); + hs.add(p); + } + long answer = 0; + while (!dq.isEmpty()) { + int size = dq.size(); + while (size--> 0) { + int[] cur = dq.poll(); + int next = cur[0] + 1; + if (!hs.contains(next)) { + dq.offer(new int[] { next, cur[1] }); + hs.add(next); + answer += Math.abs(next - cur[1]); + if (--k == 0) { + System.out.println(answer); + return; + } + } + next = cur[0] - 1; + if (!hs.contains(next)) { + dq.offer(new int[] { next, cur[1] }); + hs.add(next); + answer += Math.abs(next - cur[1]); + if (--k == 0) { + System.out.println(answer); + return; + } + } + } + } + } + + private static int read() throws Exception { + int c, n = System.in.read() & 15; + boolean m = n == 13; + if (m) + n = System.in.read() & 15; + while ((c = System.in.read())>= 48) + n = (n << 3) + (n << 1) + (c & 15); + if (c == 13) + System.in.read(); + return m ? ~n + 1 : n; + } +} From 2d2bf4858143a714aeed45282acba9640013034b Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: 2025年3月29日 17:17:11 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[BOJ]=201485?= =?UTF-8?q?2=20=ED=83=80=EC=9D=BC=20=EC=B1=84=EC=9A=B0=EA=B8=B0=203=5F2503?= =?UTF-8?q?29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/10001-15000353円262円210円/JW_14852.java" | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "BOJ/10001-15000353円262円210円/JW_14852.java" diff --git "a/BOJ/10001-15000353円262円210円/JW_14852.java" "b/BOJ/10001-15000353円262円210円/JW_14852.java" new file mode 100644 index 00000000..d7cda152 --- /dev/null +++ "b/BOJ/10001-15000353円262円210円/JW_14852.java" @@ -0,0 +1,31 @@ +import java.util.Arrays; +import java.util.PriorityQueue; + +public class JW_14852 { + static long dp[]; + static final int MOD = 1_000_000_007; + + public static void main(String[] args) throws Exception { + int n = read(); + dp = new long[n + 1]; + dp[0] = 1; + dp[1] = 2; + if (n> 1) + dp[2] = 7; + long temp = 20; + for (int i = 3; i <= n; i++) { + dp[i] = (temp + dp[i - 2]) % MOD; + temp = (temp + dp[i] * 2) % MOD; + } + System.out.println(dp[n]); + } + + private static int read() throws Exception { + int c, n = System.in.read() & 15; + while ((c = System.in.read())>= 48) + n = (n << 3) + (n << 1) + (c & 15); + if (c == 13) + System.in.read(); + return n; + } +} From d7d2b53e73647d4644c84455cef6559bf5b34770 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: 2025年3月29日 17:18:24 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[BOJ]=201644?= =?UTF-8?q?=20=EC=86=8C=EC=88=98=EC=9D=98=20=EC=97=B0=EC=86=8D=ED=95=A9=5F?= =?UTF-8?q?250329?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/1000-5000353円262円210円/JW_1644.java" | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "BOJ/1000-5000353円262円210円/JW_1644.java" diff --git "a/BOJ/1000-5000353円262円210円/JW_1644.java" "b/BOJ/1000-5000353円262円210円/JW_1644.java" new file mode 100644 index 00000000..bd2b2991 --- /dev/null +++ "b/BOJ/1000-5000353円262円210円/JW_1644.java" @@ -0,0 +1,36 @@ +import java.util.ArrayList; + +public class JW_1644 { + + public static void main(String[] args) throws Exception { + int n = read(); + int cnt = 0; + boolean[] isPrime = new boolean[n + 1]; + isPrime[0] = isPrime[1] = true; + ArrayList prime = new ArrayList(); + for (int i = 2; i < n + 1; i++) { + if (isPrime[i]) + continue; + prime.add(i); + for (int j = i * 2; j < n + 1; j += i) + isPrime[j] = true; + } + int l = 0, r = 0, sum = 0; + while (r < prime.size()) { + sum += prime.get(r); + while (sum> n && l <= r) + sum -= prime.get(l++); + if (sum == n) + cnt++; + r++; + } + System.out.println(cnt); + } + + private static int read() throws Exception { + int c, n = System.in.read() & 15; + while ((c = System.in.read())>= 48) + n = (n << 3) + (n << 1) + (c & 15); + return n; + } +} \ No newline at end of file From 8b52690d334e030bbf2e0a4689243f6a7ff46469 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: 2025年3月30日 18:20:55 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:[PG]=2072413=20?= =?UTF-8?q?=ED=95=A9=EC=8A=B9=20=ED=83=9D=EC=8B=9C=20=EC=9A=94=EA=B8=88=5F?= =?UTF-8?q?250330?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level3/JW_72413.java | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Programmers/Level3/JW_72413.java diff --git a/Programmers/Level3/JW_72413.java b/Programmers/Level3/JW_72413.java new file mode 100644 index 00000000..d2a9f59b --- /dev/null +++ b/Programmers/Level3/JW_72413.java @@ -0,0 +1,37 @@ +import java.util.Arrays; + +class JW_72413 { + public int solution(int n, int s, int a, int b, int[][] fares) { + int INF = 100_001 * n; + int answer = INF; + int[][] graph = new int[n + 1][n + 1]; + for (int i = 1; i <= n; i++) { + Arrays.fill(graph[i], INF); + graph[i][i] = 0; + } + for (int[] fare : fares) { + graph[fare[0]][fare[1]] = fare[2]; + graph[fare[1]][fare[0]] = fare[2]; + } + floydWarshall(graph, n); + for(int i = 1; i <= n; i++) { + int total = graph[s][i] + graph[i][a] + graph[i][b]; + if (total < answer) { + answer = total; + } + } + return answer; + } + + public void floydWarshall(int[][] graph, int n) { + for (int k = 1; k <= n; k++) { + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (graph[i][k] + graph[k][j] < graph[i][j]) { + graph[i][j] = graph[i][k] + graph[k][j]; + } + } + } + } + } +} \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /