Skip to content

Commit 3e388fa

Browse files
committed
교차로
1 parent 6da0b2f commit 3e388fa

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

softeer/crossroad.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import heapq
2+
3+
4+
def cast(s):
5+
t, d = s.split()
6+
return int(t), ord(d) - ord("A")
7+
8+
9+
instructions = [cast(input()) for _ in range(int(input()))]
10+
passed = [-1 for _ in instructions]
11+
12+
roads = [[] for _ in range(4)]
13+
14+
t, idx = 0, 0
15+
while True:
16+
if idx < len(instructions) and all(len(road) == 0 for road in roads):
17+
t = max(t, instructions[idx][0])
18+
19+
f = False
20+
while idx < len(instructions) and t == instructions[idx][0]:
21+
heapq.heappush(roads[instructions[idx][1]], idx)
22+
idx += 1
23+
f = True
24+
25+
if f and all(len(road) != 0 for road in roads):
26+
break
27+
28+
d_passed = []
29+
for d, road in enumerate(roads):
30+
if not road:
31+
continue
32+
if roads[(d - 1) % 4]:
33+
continue
34+
35+
passed[road[0]] = t
36+
d_passed.append(d)
37+
38+
if not d_passed:
39+
break
40+
41+
for d in d_passed:
42+
heapq.heappop(roads[d])
43+
44+
t += 1
45+
46+
for _passed in passed:
47+
print(_passed)

0 commit comments

Comments
 (0)