Skip to content

Commit 48c9bb6

Browse files
committed
123차 1번 문제풀이
1 parent 319b81b commit 48c9bb6

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
g = int(input())
6+
p = int(input())
7+
8+
gate = [i for i in range(g + 1)]
9+
10+
# gi 이하에서 가장 가까운 사용 가능한 지점 찾기
11+
def find(x):
12+
if gate[x] != x: # 이미 다른 비행기가 도킹한 경우
13+
gate[x] = find(gate[x])
14+
return gate[x]
15+
16+
def union(x, y):
17+
x = find(x)
18+
y = find(y)
19+
gate[x] = y
20+
21+
cnt = 0
22+
for _ in range(p):
23+
gi = int(input())
24+
first = find(gi)
25+
if first == 0: # 도킹 불가
26+
break
27+
union(first, first-1)
28+
cnt += 1
29+
30+
print(cnt)
31+
32+
33+
"""
34+
4
35+
6
36+
2
37+
2
38+
3
39+
3
40+
4
41+
4
42+
"""

0 commit comments

Comments
 (0)