From 37957b267d60076bf8a1728e13f36a61e4e7dc48 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Thu, 31 Jul 2025 20:44:38 +0900 Subject: [PATCH] =?UTF-8?q?[20250731]=20BOJ=20/=20G5=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=EB=B9=84?= =?UTF-8?q?=EB=B0=94=EB=9D=BC=EA=B8=B0=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\353\260\224\353\235\274\352\270\260.md" | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 "lkhyun/202507/31 BOJ G5 \353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\271\204\353\260\224\353\235\274\352\270\260.md" diff --git "a/lkhyun/202507/31 BOJ G5 \353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\271\204\353\260\224\353\235\274\352\270\260.md" "b/lkhyun/202507/31 BOJ G5 \353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\271\204\353\260\224\353\235\274\352\270\260.md" new file mode 100644 index 00000000..560db19f --- /dev/null +++ "b/lkhyun/202507/31 BOJ G5 \353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\271\204\353\260\224\353\235\274\352\270\260.md" @@ -0,0 +1,93 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,M; + static int[][] matrix; + static List shiftList; + static List cloudList; + static int[] di = {0,0,-1,-1,-1,0,1,1,1}; + static int[] dj = {0,-1,-1,0,1,1,1,0,-1}; + + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + matrix = new int[N+1][N+1]; + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 1; j <= N; j++) { + matrix[i][j] = Integer.parseInt(st.nextToken()); + } + } + + shiftList = new ArrayList<>(M); + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + shiftList.add(new int[]{Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken())}); + } + + cloudList = new ArrayList<>(); + cloudList.add(new int[]{N,1}); + cloudList.add(new int[]{N,2}); + cloudList.add(new int[]{N-1,1}); + cloudList.add(new int[]{N-1,2}); + + for (int[] curShift : shiftList) { + int cloudSize = cloudList.size(); + for (int i = 0; i < cloudSize; i++) { + int[] cur = cloudList.get(i); + shift(cur, curShift[0],curShift[1]); + matrix[cur[0]][cur[1]]++; + } + + for (int i = 0; i < cloudSize; i++) { + int[] cur = cloudList.get(i); + for (int j = 2; j <= 8; j+=2) { + int ni = cur[0] + di[j]; + int nj = cur[1] + dj[j]; + if(ni>=1 && ni<=N && nj>=1 && nj<=N && matrix[ni][nj]>0){ + matrix[cur[0]][cur[1]]++; + } + } + } + + boolean[][] visited = new boolean[N+1][N+1]; + for (int[] cur : cloudList) { + visited[cur[0]][cur[1]] = true; + } + cloudList.clear(); + + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= N; j++) { + if(!visited[i][j] && matrix[i][j]>=2){ + cloudList.add(new int[]{i,j}); + matrix[i][j] -= 2; + } + } + } + } + + int ans = 0; + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= N; j++) { + ans += matrix[i][j]; + } + } + bw.write(ans+""); + bw.close(); + } + static void shift(int[] cur, int direction, int count){ + cur[0] += di[direction]*count; + cur[1] += dj[direction]*count; + + cur[0] = (((cur[0] - 1) % N) + N) % N + 1; + cur[1] = (((cur[1] - 1) % N) + N) % N + 1; + } +} +```