-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdestroy_the_chip.py
More file actions
127 lines (118 loc) · 3.36 KB
/
destroy_the_chip.py
File metadata and controls
127 lines (118 loc) · 3.36 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import sys
lx, rx, ly, ry = 0,0,0,0
def HellofFire(midx, midy):
global lx, rx, ly, ry, cnt
cnt += 1
answer = input()
if answer == "O":
return "success"
elif answer == "PY":
rx = midx-1
return "Y"
elif answer == "NY":
lx = midx+1
return 'Y'
elif answer == "XP":
ry = midy-1
return 'X'
elif answer == "XN":
ly = midy+1
return 'X'
elif answer == "PP":
rx = midx - 1
ry = midy - 1
elif answer == "PN":
rx = midx - 1
ly = midy + 1
elif answer == "NP":
lx = midx + 1
ry = midy - 1
elif answer == "NN":
lx = midx + 1
ly = midy + 1
else:
cnt-=1
if answer == "FAILED":
#print("failed either due to excess queries or invalid attack statement")
exit(0)
def RingofFire(lx, rx, ly, ry):
global cnt
cnt+=1
print(2, lx, ly, rx, ry)
answer = input()
if answer == 'IN':
return RingofFire(lx, rx, ly, ry)
elif answer == 'O':
return 'success'
def BinarySearch():
global cnt, q, lx, rx, ly, ry
#lx, rx, ly, ry = -62, -60, -1, 8
lx, rx, ly, ry = int(-2e18), int(2e18), int(-2e18), int(2e18)
while lx<=rx or ly<=ry:
midx = (lx+rx)//2
midy = (ly+ry)//2
print(1, midx, midy, flush=True)
sys.stdout.flush()
output1 = HellofFire(midx, midy)
if output1 == 'success':
return
lx-=1
rx+=1
ly-=1
ry+=1
#print(f'lx = %d, rx = %d, ly = %d, ry = %d' %(lx, rx, ly, ry))
if rx-lx == 2 and ry-ly == 2:
output2 = RingofFire(lx, rx, ly, ry)
if output2 == 'success':
return
elif rx - lx == 2 and output1 == "Y":
output2 = RingofFire(lx, rx, midy - 1, midy + 1)
if output2 == 'success':
return
elif ry - ly == 2 and output1 == "X":
output2 = RingofFire(midx - 1, midx + 1, ly, ry)
if output2 == 'success':
return
if cnt > q:
print('FAIL')
exit(0)
#brackets(5)
t, q, d = map(int, input().split())
for i in range(t):
cnt = 0
if d == 0:
lx, rx, ly, ry = int(-2e18), int(2e18), int(-2e18), int(2e18)
while lx<=rx or ly<=ry:
cnt += 1
midx = (lx+rx)//2
midy = (ly+ry)//2
print(1, midx, midy, flush=True)
sys.stdout.flush()
answer = input()
if answer == "O":
break
elif answer == "PY":
rx = midx-1
elif answer == "NY":
lx = midx+1
elif answer == "XP":
ry = midy-1
elif answer == "XN":
ly = midy+1
elif answer == "PP":
rx = midx - 1
ry = midy - 1
elif answer == "PN":
rx = midx - 1
ly = midy + 1
elif answer == "NP":
lx = midx + 1
ry = midy - 1
elif answer == "NN":
lx = midx + 1
ly = midy + 1
if answer == "FAILED" or cnt > q:
#print("failed either due to excess queries or invalid attack statement")
exit(0)
continue
BinarySearch()