-
Notifications
You must be signed in to change notification settings - Fork 0
/
15.py
executable file
·56 lines (42 loc) · 1.03 KB
/
15.py
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
#!/usr/bin/env pypy3
# 27/209
from util import *
if len(sys.argv) == 1:
sys.stdin = open(__file__.replace("py", "in"))
res = 0
boxes = [[] for _ in range(256)]
lab_strength = {}
for seq in input().split(","):
if "-" in seq:
assert seq[-1] == "-"
op = "-"
seq = seq[:-1]
else:
assert "=" in seq
seq, fl = seq.split("=")
op = "="
fl = int(fl)
h = 0
for c in seq:
h = (h + ord(c)) * 17 % 256
# res += h
if op == "-":
s = lab_strength.get(seq)
if seq in boxes[h]:
boxes[h].remove(seq)
else:
lab_strength[seq] = fl
for i, oseq in enumerate(boxes[h]):
if oseq == seq:
boxes[h][i] = seq
break
else:
boxes[h].append(seq)
for bi, b in enumerate(boxes, 1):
if b:
print(bi, b)
for bi, b in enumerate(boxes, 1):
for li, seq in enumerate(b, 1):
res += bi * li * lab_strength[seq]
# lab_to_box[seq] = (bi, li)
prints(res)