-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path24.py
41 lines (33 loc) · 764 Bytes
/
24.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
from lib import *
input = read_input(2021, 24)
lines = input.splitlines()
stack = []
out = [9] * 14
for i in range(14):
x = int(lines[i * 18 + 5].split()[2])
y = int(lines[i * 18 + 15].split()[2])
if x < 0:
j, y = stack.pop()
x += y
if x < 0:
out[i] += x
else:
out[j] -= x
else:
stack.append((i, y))
print(int("".join(map(str, out))))
stack = []
out = [1] * 14
for i in range(14):
x = int(lines[i * 18 + 5].split()[2])
y = int(lines[i * 18 + 15].split()[2])
if x < 0:
j, y = stack.pop()
x += y
if x < 0:
out[j] -= x
else:
out[i] += x
else:
stack.append((i, y))
print(int("".join(map(str, out))))