File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments