From 6f6c0ffbe849c0e7f07dbdc76363b658e448871d Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Tue, 8 Jul 2025 20:15:11 +0900 Subject: [PATCH] =?UTF-8?q?[20250708]=20BOJ=20/=20G2=20/=20=EA=B3=B5?= =?UTF-8?q?=ED=95=AD=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 --- .../8 BOJ G2 \352\263\265\355\225\255.md" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "lkhyun/202507/8 BOJ G2 \352\263\265\355\225\255.md" diff --git "a/lkhyun/202507/8 BOJ G2 \352\263\265\355\225\255.md" "b/lkhyun/202507/8 BOJ G2 \352\263\265\355\225\255.md" new file mode 100644 index 00000000..5488a72e --- /dev/null +++ "b/lkhyun/202507/8 BOJ G2 \352\263\265\355\225\255.md" @@ -0,0 +1,42 @@ +```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 int G,P; + static int[] nextBlank; + static int count = 0; + public static void main(String[] args) throws Exception{ + G = Integer.parseInt(br.readLine()); + P = Integer.parseInt(br.readLine()); + nextBlank = new int[G+1]; //빈 공간 가리키기 + + for (int i = 1; i <= G; i++) { + nextBlank[i] = i; + } + + for (int i = 1; i <= P; i++) { + int gi = Integer.parseInt(br.readLine()); + int blank = find(gi); //빈 공간 찾기 + if(blank == 0){ + break; + }else{ + count++; + nextBlank[blank] = nextBlank[blank-1]; + } + } + + bw.write(String.valueOf(count)); + bw.close(); + } + static int find(int gi){ + if(nextBlank[gi] == gi){ + return gi; + }else{ + return nextBlank[gi] = find(nextBlank[gi]); + } + } +} +```