-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempo.py
More file actions
61 lines (54 loc) · 1.4 KB
/
tempo.py
File metadata and controls
61 lines (54 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Time, 2021 Brazilian Informatics Olympiad
# Available @ https://olimpiada.ic.unicamp.br/pratique/p2/2021/f1/tempo/
n = int(input())
events = []
final = []
for i in range(n): # Adjacent list
events.append([str(i) for i in input().split(' ')])
for i in range(n): # Calculate every friend
if events[i][0] == 'R':
current = events[i][1]
time = 0
last = 0
for j in range(i + 1, n): # Search for the answer
if last:
if events[j][0] == 'E' and events[j][1] == current:
final.append([current, time])
break
else:
last = 0
continue;
else:
if events[j][0] == 'E' and events[j][1] == current:
final.append([current, time + 1])
break
elif j == (n - 1):
final.append([current, -1])
break
elif events[j][0] == 'T':
time += int(events[j][1])
last = 1
continue
else:
time += 1
continue
names = []
times = []
passe = []
for i in range(len(final)):
if final[i][0] not in passe:
names.append(final[i][0])
times.append(final[i][1])
passe.append(final[i][0])
else:
index_passed = names.index(final[i][0])
if final[i][1] == -1:
times[index_passed] = -1
else:
times[index_passed] += final[i][1]
final = []
for i in range(len(times)):
final.append([names[i], times[i]])
final.sort(key=lambda x: x[0])
for i in range(len(final)):
print(final[i][0],final[i][1])