From a1339dcd1cce78be800eca0092f6be073fff860d Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Thu, 7 Aug 2025 23:57:50 +0900 Subject: [PATCH] =?UTF-8?q?[20250807]=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=EA=B0=95?= =?UTF-8?q?=ED=98=84?= 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 "lkhyun/202508/07 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/lkhyun/202508/07 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/lkhyun/202508/07 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..7b8d165c --- /dev/null +++ "b/lkhyun/202508/07 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 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); + int K = Integer.parseInt(st.nextToken()); + + int[] belt = new int[2 * N]; + boolean[] robot = new boolean[2 * N]; + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < 2 * N; i++) { + belt[i] = Integer.parseInt(st.nextToken()); + } + + int step = 0; + + while (true) { + step++; + + int tempBelt = belt[2 * N - 1]; + boolean tempRobot = robot[2 * N - 1]; + + for (int i = 2 * N - 1; i > 0; i--) { + belt[i] = belt[i - 1]; + robot[i] = robot[i - 1]; + } + + belt[0] = tempBelt; + robot[0] = tempRobot; + + if (robot[N - 1]) { + robot[N - 1] = false; + } + + for (int i = N - 2; i >= 0; i--) { + if (robot[i] && !robot[i + 1] && belt[i + 1] > 0) { + robot[i] = false; + robot[i + 1] = true; + belt[i + 1]--; + + if (i + 1 == N - 1) { + robot[i + 1] = false; + } + } + } + + if (!robot[0] && belt[0] > 0) { + robot[0] = true; + belt[0]--; + } + + int zeroCount = 0; + for (int i = 0; i < 2 * N; i++) { + if (belt[i] == 0) { + zeroCount++; + } + } + + if (zeroCount >= K) { + break; + } + } + + bw.write(step+""); + bw.close(); + } +} +```