From f8af9c7668c3c1195c3e9e2a8063da56efebbe24 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Thu, 4 Dec 2025 10:25:23 +0900 Subject: [PATCH] =?UTF-8?q?[20251204]=20BOJ=20/=20G3=20/=20=EB=A7=88?= =?UTF-8?q?=EB=B2=95=EC=82=AC=20=EC=83=81=EC=96=B4=EC=99=80=20=ED=86=A0?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=8F=84=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\353\204\244\354\235\264\353\217\204.md" | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 "JHLEE325/202512/04 BOJ G3 \353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \355\206\240\353\204\244\354\235\264\353\217\204.md" diff --git "a/JHLEE325/202512/04 BOJ G3 \353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \355\206\240\353\204\244\354\235\264\353\217\204.md" "b/JHLEE325/202512/04 BOJ G3 \353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \355\206\240\353\204\244\354\235\264\353\217\204.md" new file mode 100644 index 00000000..aecd890d --- /dev/null +++ "b/JHLEE325/202512/04 BOJ G3 \353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \355\206\240\353\204\244\354\235\264\353\217\204.md" @@ -0,0 +1,105 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int[][] A; + static int answer; + + static int[] dx = {0, 1, 0, -1}; + static int[] dy = {-1, 0, 1, 0}; + + static int[][] dsx = { + { -1, 1, -2, -1, 1, 2, -1, 1, 0 }, + { -1, -1, 0, 0, 0, 0, 1, 1, 2 }, + { 1, -1, 2, 1, -1, -2, 1, -1, 0 }, + { 1, 1, 0, 0, 0, 0, -1, -1, -2 } + }; + + static int[][] dsy = { + { 1, 1, 0, 0, 0, 0, -1, -1, -2 }, + { -1, 1, -2, -1, 1, 2, -1, 1, 0 }, + { -1, -1, 0, 0, 0, 0, 1, 1, 2 }, + { 1, -1, 2, 1, -1, -2, 1, -1, 0 } + }; + + static int[] ratio = {1, 1, 2, 7, 7, 2, 10, 10, 5}; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + N = Integer.parseInt(br.readLine()); + A = new int[N][N]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + A[i][j] = Integer.parseInt(st.nextToken()); + } + } + + simulate(); + System.out.println(answer); + } + + static void simulate() { + int x = N/2; + int y = N/2; + + int len = 1; + int dir = 0; + + while (true) { + for (int i = 0; i < 2; i++) { + for (int step = 0; step < len; step++) { + + x += dx[dir]; + y += dy[dir]; + + spread(x, y, dir); + + if (x == 0 && y == 0) return; + } + dir = (dir + 1) % 4; + } + len++; + } + } + + static void spread(int x, int y, int dir) { + int sand = A[x][y]; + if (sand == 0) { + return; + } + A[x][y] = 0; + + int used = 0; + + for (int i = 0; i < 9; i++) { + int nx = x + dsx[dir][i]; + int ny = y + dsy[dir][i]; + + int amount = (sand * ratio[i]) / 100; + used += amount; + + if (nx < 0 || ny < 0 || nx >= N || ny >= N) { + answer += amount; + } else { + A[nx][ny] += amount; + } + } + + int ax = x + dx[dir]; + int ay = y + dy[dir]; + int remain = sand - used; + + if (ax < 0 || ay < 0 || ax >= N || ay >= N) { + answer += remain; + } else { + A[ax][ay] += remain; + } + } +} +```