-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.py
More file actions
80 lines (63 loc) · 1.92 KB
/
score.py
File metadata and controls
80 lines (63 loc) · 1.92 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from collections import defaultdict
class Intersection(object):
def __init__(self, id, inc_streets, streets):
self.id = id
self.inc_streets = inc_streets
self.streets = []
self.queue = {} # streetname -> list(car.id)
def append(self, street):
self.streets.append(street)
class Car(object):
def __init__(self, id, curr, time, path):
self.id = id
self.curr = curr # int
self.time = time # int
self.path = path # str[]
def score(in_str, out_str):
in_str.seek(0)
out_str = out_str.split('\n')
line1 = [int(x) for x in in_str.readline().strip().split(' ')]
D = line1[0]
I = line1[1]
S = line1[2]
V = line1[3]
F = line1[4]
s = 0
world = {}
# Street descriptions
while s < S:
line = in_str.readline().strip().split(' ')
B = int(line[0])
E = int(line[1])
street_name = line[2]
L = int(line[3])
s += 1
world[street_name] = (B, E)
v = 0
cars = dict()
queues = defaultdict(list)
# Paths of each car
while v < V:
line = in_str.readline().strip().split(' ')
P = int(line[0])
path = line[1:]
for p in range(P):
street = line[p]
cars[v] = Car(v, 0, 0, path)
v += 1
map = dict()
intersections = int(out_str[0].strip())
idx = 1
while idx < len(out_str):
id = int(out_str[idx].strip())
inc_streets = int(out_str[idx+1])
intersection = Intersection(id, inc_streets, [])
for j in range(inc_streets):
street_name, duration = out_str[idx+j+2].split(' ')
intersection.append((street_name, duration))
map[id] = intersection
idx += inc_streets + 2
# Init all queues
for car in cars.values():
queues[car.path[car.curr]].append(car.id)
# This was a waste of time, let's just leave the code here