Skip to content

Commit 6f6c0ff

Browse files
authored
[20250708] BOJ / G2 / 공항 / 이강현
1 parent ce08215 commit 6f6c0ff

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

lkhyun/202507/8 BOJ G2 공항.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static int G,P;
9+
static int[] nextBlank;
10+
static int count = 0;
11+
public static void main(String[] args) throws Exception{
12+
G = Integer.parseInt(br.readLine());
13+
P = Integer.parseInt(br.readLine());
14+
nextBlank = new int[G+1]; //빈 공간 가리키기
15+
16+
for (int i = 1; i <= G; i++) {
17+
nextBlank[i] = i;
18+
}
19+
20+
for (int i = 1; i <= P; i++) {
21+
int gi = Integer.parseInt(br.readLine());
22+
int blank = find(gi); //빈 공간 찾기
23+
if(blank == 0){
24+
break;
25+
}else{
26+
count++;
27+
nextBlank[blank] = nextBlank[blank-1];
28+
}
29+
}
30+
31+
bw.write(String.valueOf(count));
32+
bw.close();
33+
}
34+
static int find(int gi){
35+
if(nextBlank[gi] == gi){
36+
return gi;
37+
}else{
38+
return nextBlank[gi] = find(nextBlank[gi]);
39+
}
40+
}
41+
}
42+
```

0 commit comments

Comments
 (0)