-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday15.2.py
64 lines (57 loc) · 949 Bytes
/
day15.2.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
57
58
59
60
61
62
63
64
sns = []
while True:
l = input()
if(l[0] == '~'):
break
l = l.split(' ')
xp = int(l[2][2:-1])
yp = int(l[3][2:-1])
xb = int(l[8][2:-1])
yb = int(l[9][2:])
#print(f"{xp} {yp} {xb} {yb}")
cs = [(xp, yp), abs(xp - xb) + abs(yp - yb)]
#ab.append((xb, yb))
sns.append(cs)
ub = 4000000
#ub = 20
def ok(x, y):
if x > ub or y > ub or x < 0 or y < 0:
return False
for s in sns:
if abs(x - s[0][0]) + abs(y - s[0][1]) <= s[1]:
return False
return True
fx = -1
fy = -1
cnt = 0
for s in sns:
print(s)
x = s[0][0]
y = s[0][1]
d = s[1]
for i in range(-d, d+1):
cx = x + i
ad = d - abs(i)
cy1 = y+ad+1
cy2 = y-ad-1
if(ok(cx, cy1)):
fx = cx
fy = cy1
cn
if(ok(cx, cy2)):
fx = cx
fy = cy2
for i in range(-d, d+1):
cy = y + i
ad = d - abs(i)
cx1 = x+ad+1
cx2 = x-ad-1
if(ok(cx1, cy)):
fx = cx1
fy = cy
if(ok(cx2, cy)):
fx = cx2
fy = cy
print(fx)
print(fy)
print(fx * 4000000 + fy)