From 2908ea0025fce6e7288679941b671747e1ebb9fb Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Thu, 4 Sep 2025 08:25:40 +0900 Subject: [PATCH] =?UTF-8?q?[20250904]=20BOJ=20/=20G5=20/=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=96=B4=20=EB=B2=A8=ED=8A=B8=20=EC=9C=84?= =?UTF-8?q?=EC=9D=98=20=EB=A1=9C=EB=B4=87=20/=20=EC=9D=B4=EC=A4=80?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\235\230 \353\241\234\353\264\207.md" | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "JHLEE325/202509/04 BOJ G5 \354\273\250\353\262\240\354\235\264\354\226\264 \353\262\250\355\212\270 \354\234\204\354\235\230 \353\241\234\353\264\207.md" diff --git "a/JHLEE325/202509/04 BOJ G5 \354\273\250\353\262\240\354\235\264\354\226\264 \353\262\250\355\212\270 \354\234\204\354\235\230 \353\241\234\353\264\207.md" "b/JHLEE325/202509/04 BOJ G5 \354\273\250\353\262\240\354\235\264\354\226\264 \353\262\250\355\212\270 \354\234\204\354\235\230 \353\241\234\353\264\207.md" new file mode 100644 index 00000000..a063ac02 --- /dev/null +++ "b/JHLEE325/202509/04 BOJ G5 \354\273\250\353\262\240\354\235\264\354\226\264 \353\262\250\355\212\270 \354\234\204\354\235\230 \353\241\234\353\264\207.md" @@ -0,0 +1,75 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int n, k; + static int[] str; + static boolean[] robot; + + 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()); + k = Integer.parseInt(st.nextToken()); + + str = new int[2 * n]; + robot = new boolean[n]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < 2 * n; i++) { + str[i] = Integer.parseInt(st.nextToken()); + } + + int stage = 0; + while (true) { + stage++; + + int laststr = str[2 * n - 1]; + for (int i = 2 * n - 1; i > 0; i--) { + str[i] = str[i - 1]; + } + str[0] = laststr; + + for (int i = n - 1; i > 0; i--) { + robot[i] = robot[i - 1]; + } + robot[0] = false; + + if (robot[n - 1]) { + robot[n - 1] = false; + } + + for (int i = n - 2; i >= 0; i--) { + if (robot[i] && !robot[i + 1] && str[i + 1] >= 1) { + robot[i] = false; + robot[i + 1] = true; + str[i + 1]--; + } + } + + if (robot[n - 1]) { + robot[n - 1] = false; + } + + if (str[0] > 0) { + robot[0] = true; + str[0]--; + } + + int zerostr = 0; + for (int d : str) { + if (d == 0) { + zerostr++; + } + } + if (zerostr >= k) { + break; + } + } + + System.out.println(stage); + } +} +```