s_id string | p_id string | u_id string | date string | language string | original_language string | filename_ext string | status string | cpu_time string | memory string | code_size string | code string | error string | stdout string |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s322646715 | p02289 | u112247126 | 1487833103 | Python | Python3 | py | Runtime Error | 0 | 0 | 1106 | import sys
from numpy import inf
def insert(heap, key):
heap.append(-inf)
heapIncreaseKey(heap, key)
def parent(i):
return (i - 1) // 2
def heapIncreaseKey(heap, key):
heap[len(heap) - 1] = key
i = len(heap) - 1
while i > 0 and heap[parent(i)] < heap[i]:
heap[i], heap[parent(i)] = heap[parent(i)], heap[i]
i = parent(i)
def heapExtractMax(heap):
if len(heap) < 1:
return None
else:
MAX = heap[0]
heap[0] = heap.pop()
maxHeapify(heap, 0)
return MAX
def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if left < len(heap) and heap[left] > heap[i] else i
largest = right if right < len(heap) and heap[right] > heap[largest] else largest
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
maxHeapify(heap, largest)
heap = []
out = ''
while True:
line = stdin.readline()
if line[0] == 'i':
insert(heap, int(line.split()[1]))
elif line[0:2] == 'ex':
print(str(heapExtractMax(heap)))
else:
break | Traceback (most recent call last):
File "/tmp/tmpp1r38m5t/tmp5a0kx9dv.py", line 41, in <module>
line = stdin.readline()
^^^^^
NameError: name 'stdin' is not defined
| |
s215176537 | p02289 | u112247126 | 1487833266 | Python | Python3 | py | Runtime Error | 0 | 0 | 1101 | import sys
from numpy import inf
def insert(heap, key):
heap.append(-inf)
heapIncreaseKey(heap, key)
def parent(i):
return (i - 1) // 2
def heapIncreaseKey(heap, key):
heap[len(heap) - 1] = key
i = len(heap) - 1
while i > 0 and heap[parent(i)] < heap[i]:
heap[i], heap[parent(i)] = heap[parent(i)], heap[i]
i = parent(i)
def heapExtractMax(heap):
if len(heap) < 1:
return None
else:
MAX = heap[0]
heap[0] = heap.pop()
maxHeapify(heap, 0)
return MAX
def maxHeapify(heap, i):
left = (i + 1) * 2 - 1
right = (i + 1) * 2
largest = left if left < len(heap) and heap[left] > heap[i] else i
largest = right if right < len(heap) and heap[right] > heap[largest] else largest
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
maxHeapify(heap, largest)
heap = []
while True:
line = sys.stdin.readline()
if line[0] == 'i':
insert(heap, int(line.split()[1]))
elif line[0:2] == 'ex':
print(str(heapExtractMax(heap)))
else:
break | Traceback (most recent call last):
File "/tmp/tmp8h58bqtx/tmp8qwysoe9.py", line 41, in <module>
if line[0] == 'i':
~~~~^^^
IndexError: string index out of range
| |
s481653155 | p02289 | u546285759 | 1492335251 | Python | Python3 | py | Runtime Error | 0 | 0 | 335 | import bisect
from collections import deque
maxv = 0
l = deque()
while True:
order = input()
if order == "end":
break
tmp = order.split()
if len(tmp) > 1:
v = int(tmp[1])
bisect.insort(l, v)
maxv = l[-1]
else:
print(maxv)
l.pop()
maxv = l[-1] if len(l) else 0 | Traceback (most recent call last):
File "/tmp/tmp04vpvt04/tmp8a7phf40.py", line 6, in <module>
order = input()
^^^^^^^
EOFError: EOF when reading a line
| |
s281568507 | p02289 | u370086573 | 1494575770 | Python | Python3 | py | Runtime Error | 0 | 0 | 1102 | import sys
heap = [0]
NIL = -1
def parent(i):
return i // 2
def left(i):
return 2 * i
def right(i):
return 2 * i + 1
def insert(key):
H = len(heap) - 1
heap.append(NIL)
heapIncreaseKey(H, key)
def heapIncreaseKey(i, key):
if key < heap[i]:
return False
heap[i] = key
while i > 1 and heap[parent(i)] < heap[i]:
heap[i], heap[parent(i)] = heap[parent(i)], heap[i]
i = parent(i)
def heapExtractMax():
H = len(heap) - 1
if H < 1:
return False
max = heap[1]
heap[1] = heap[H]
heap.pop(H)
maxHeapify(1)
return max
def maxHeapify(i):
H = len(heap) - 1
l = left(i)
r = right(i)
if l <= H and heap[l] > heap[i]:
largest = l
else:
largest = i
if r <= H and heap[r] > heap[largest]:
largest = r
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
maxHeapify(largest)
for com in sys.stdin.readlines():
if com[0] == "i":
heap.insert(int(com[7:]))
elif com[1] == "x":
print(heap.heapExtractMax()) | ||
s397655964 | p02289 | u370086573 | 1494576402 | Python | Python3 | py | Runtime Error | 0 | 0 | 1102 | def parent(i):
return i // 2
def left(i):
return 2 * i
def right(i):
return 2 * i + 1
def insert(key):
heap.append(NIL)
H = len(heap) - 1
heapIncreaseKey(H, key)
def heapIncreaseKey(i, key):
if key < heap[i]:
return False
heap[i] = key
while i > 1 and heap[parent(i)] < heap[i]:
heap[i], heap[parent(i)] = heap[parent(i)], heap[i]
i = parent(i)
def heapExtractMax():
H = len(heap) - 1
if H < 1:
return False
max = heap[1]
heap[1] = heap[H]
heap.pop(H)
maxHeapify(1)
return max
def maxHeapify(i):
H = len(heap) - 1
l = left(i)
r = right(i)
if l <= H and heap[l] > heap[i]:
largest = l
else:
largest = i
if r <= H and heap[r] > heap[largest]:
largest = r
if largest != i:
heap[i], heap[largest] = heap[largest], heap[i]
maxHeapify(largest)
while True:
cmd = list(input().split())
if cmd[0] == 'insert':
insert(int(cmd[1]))
elif cmd[0] == 'extract':
print(heapExtractMax())
else:
break | Traceback (most recent call last):
File "/tmp/tmpeyxtmt9n/tmp5kl9c75q.py", line 57, in <module>
cmd = list(input().split())
^^^^^^^
EOFError: EOF when reading a line
| |
s415356911 | p02289 | u990398499 | 1499326550 | Python | Python3 | py | Runtime Error | 0 | 0 | 1407 | # ?§£???2
from math import inf
from math import floor
def maxheapfi(i):
global H
global A
l = 2 * (i + 1) - 1
r = 2 * (i + 1)
if l < H and A[l] > A[i-1] :
largest = l
else:
largest = i
if r < H and A[r] > A[largest] :
largest = r
if largest != i:
tmp = A[i-1]
A[i-1] = A[largest]
A[largest] = tmp
maxheapfi(largest,A,H)
def extract():
global H
global A
if H < 0 : return -inf
maxv = A[0]
A[0] = A[H-1]
H -= 1
maxheapfi(0)
return maxv
def increasekey(i, key):
global H
global A
if key < A[i - 1]:
return
A[i - 1] = key
while( i > 0 and A[floor(i/2)-1] < A[i-1]):
tmp = A[i-1]
A[i - 1] = A[floor(i/2) - 1]
A[floor(i/2) - 1] = tmp
i = floor(i/2) - 1
def insert(key):
global H
global A
H += 1
if len(A) <= H:
A.append(-inf)
else:
A[H-1] = -inf
increasekey(H,key)
def main():
global H
global A
H = 0
A = []
opr = [x.strip().split(' ') for x in open('./input/B1.txt').readlines()]
H = int(input().strip())
For i in range(H):
opr.append(input().strip().split(??? ???))
for i in opr:
if i[0] == 'insert':
insert(int(i[1]))
if i[0] == 'extract':
print(extract())
main() | File "/tmp/tmpu3674hi4/tmp39d0rpg5.py", line 65
For i in range(H):
^
SyntaxError: invalid syntax
| |
s195803451 | p02289 | u990398499 | 1499326711 | Python | Python3 | py | Runtime Error | 0 | 0 | 1404 | # ?§£???2
from math import inf
from math import floor
def maxheapfi(i):
global H
global A
l = 2 * (i + 1) - 1
r = 2 * (i + 1)
if l < H and A[l] > A[i-1] :
largest = l
else:
largest = i
if r < H and A[r] > A[largest] :
largest = r
if largest != i:
tmp = A[i-1]
A[i-1] = A[largest]
A[largest] = tmp
maxheapfi(largest,A,H)
def extract():
global H
global A
if H < 0 : return -inf
maxv = A[0]
A[0] = A[H-1]
H -= 1
maxheapfi(0)
return maxv
def increasekey(i, key):
global H
global A
if key < A[i - 1]:
return
A[i - 1] = key
while( i > 0 and A[floor(i/2)-1] < A[i-1]):
tmp = A[i-1]
A[i - 1] = A[floor(i/2) - 1]
A[floor(i/2) - 1] = tmp
i = floor(i/2) - 1
def insert(key):
global H
global A
H += 1
if len(A) <= H:
A.append(-inf)
else:
A[H-1] = -inf
increasekey(H,key)
def main():
global H
global A
H = 0
A = []
#opr = [x.strip().split(' ') for x in open('./input/B1.txt').readlines()]
H = int(input().strip())
for i in range(H):
opr.append(input().strip().split(' '))
for i in opr:
if i[0] == 'insert':
insert(int(i[1]))
if i[0] == 'extract':
print(extract())
main() | Traceback (most recent call last):
File "/tmp/tmpv2vudmv0/tmpwjie1o4o.py", line 73, in <module>
main()
File "/tmp/tmpv2vudmv0/tmpwjie1o4o.py", line 64, in main
H = int(input().strip())
^^^^^^^
EOFError: EOF when reading a line
| |
s464530114 | p02289 | u990398499 | 1499328051 | Python | Python3 | py | Runtime Error | 0 | 0 | 1450 | # ?§£???2
from math import inf
from math import floor
def maxheapfi(i):
global H
global A
l = 2 * (i) + 1
r = 2 * (i +1)
if l < H and A[l] > A[i] :
largest = l
else:
largest = i
if r < H and A[r] > A[largest] :
largest = r
#print('largest',largest)
if largest != i:
tmp = A[i]
A[i] = A[largest]
A[largest] = tmp
maxheapfi(largest)
def extract():
global H
global A
if H < 0 : return -inf
maxv = A[0]
A[0] = A[H-1]
H -= 1
maxheapfi(0)
#print(32,A)
return maxv
def increasekey(i, key):
global H
global A
if key < A[i]:
return
A[i] = key
while( i > 0 and A[floor(i/2)] < A[i]):
tmp = A[i]
A[i] = A[floor(i/2) ]
A[floor(i/2)] = tmp
i = floor(i/2)
#print(46,i,key,A)
def insert(key):
global H
global A
H += 1
if len(A) < H:
A.append(-inf)
else:
A[H-1] = -inf
#print('increasekey',H-1,key)
increasekey(H-1,key)
def main():
global H
global A
H = 0
A = []
opr = None
count = 0
while(True):
opr = input().strip().split(' ')
if opr[0] == 'insert':
insert(int(opr[1]))
#print(A)
if opr[0] == 'extract':
print(extract())
#print(A)
if opr[0] == 'end':
break
main() | Traceback (most recent call last):
File "/tmp/tmpu76uhd9a/tmp12zz30na.py", line 79, in <module>
main()
File "/tmp/tmpu76uhd9a/tmp12zz30na.py", line 69, in main
opr = input().strip().split(' ')
^^^^^^^
EOFError: EOF when reading a line
| |
s532818009 | p02289 | u990398499 | 1499328140 | Python | Python3 | py | Runtime Error | 0 | 0 | 1450 | # ?§£???2
from math import inf
from math import floor
def maxheapfi(i):
global H
global A
l = 2 * (i) + 1
r = 2 * (i +1)
if l < H and A[l] > A[i] :
largest = l
else:
largest = i
if r < H and A[r] > A[largest] :
largest = r
#print('largest',largest)
if largest != i:
tmp = A[i]
A[i] = A[largest]
A[largest] = tmp
maxheapfi(largest)
def extract():
global H
global A
if H < 0 : return -inf
maxv = A[0]
A[0] = A[H-1]
H -= 1
maxheapfi(0)
#print(32,A)
return maxv
def increasekey(i, key):
global H
global A
if key < A[i]:
return
A[i] = key
while( i > 0 and A[floor(i/2)] < A[i]):
tmp = A[i]
A[i] = A[floor(i/2) ]
A[floor(i/2)] = tmp
i = floor(i/2)
#print(46,i,key,A)
def insert(key):
global H
global A
H += 1
if len(A) < H:
A.append(-inf)
else:
A[H-1] = -inf
#print('increasekey',H-1,key)
increasekey(H-1,key)
def main():
global H
global A
H = 0
A = []
opr = None
count = 0
while(True):
opr = input().strip().split(' ')
if opr[0] == 'insert':
insert(int(opr[1]))
#print(A)
if opr[0] == 'extract':
print(extract())
#print(A)
if opr[0] == 'end':
break
main() | Traceback (most recent call last):
File "/tmp/tmp_gx3wdbf/tmpuccu7d9a.py", line 79, in <module>
main()
File "/tmp/tmp_gx3wdbf/tmpuccu7d9a.py", line 69, in main
opr = input().strip().split(' ')
^^^^^^^
EOFError: EOF when reading a line
| |
s267641186 | p02289 | u990398499 | 1499328184 | Python | Python3 | py | Runtime Error | 0 | 0 | 1438 | from math import inf
from math import floor
def maxheapfi(i):
global H
global A
l = 2 * (i) + 1
r = 2 * (i +1)
if l < H and A[l] > A[i] :
largest = l
else:
largest = i
if r < H and A[r] > A[largest] :
largest = r
#print('largest',largest)
if largest != i:
tmp = A[i]
A[i] = A[largest]
A[largest] = tmp
maxheapfi(largest)
def extract():
global H
global A
if H < 0 : return -inf
maxv = A[0]
A[0] = A[H-1]
H -= 1
maxheapfi(0)
#print(32,A)
return maxv
def increasekey(i, key):
global H
global A
if key < A[i]:
return
A[i] = key
while( i > 0 and A[floor(i/2)] < A[i]):
tmp = A[i]
A[i] = A[floor(i/2) ]
A[floor(i/2)] = tmp
i = floor(i/2)
#print(46,i,key,A)
def insert(key):
global H
global A
H += 1
if len(A) < H:
A.append(-inf)
else:
A[H-1] = -inf
#print('increasekey',H-1,key)
increasekey(H-1,key)
def main():
global H
global A
H = 0
A = []
opr = None
count = 0
while(True):
opr = input().strip().split(' ')
if opr[0] == 'insert':
insert(int(opr[1]))
#print(A)
if opr[0] == 'extract':
print(extract())
#print(A)
if opr[0] == 'end':
break
main() | Traceback (most recent call last):
File "/tmp/tmprv0x9zhf/tmpm4jtnjtf.py", line 78, in <module>
main()
File "/tmp/tmprv0x9zhf/tmpm4jtnjtf.py", line 68, in main
opr = input().strip().split(' ')
^^^^^^^
EOFError: EOF when reading a line
| |
s929604579 | p02289 | u796784914 | 1500703270 | Python | Python | py | Runtime Error | 0 | 0 | 1037 | from collections import deque
def main():
q =deque()
H = 0
for i in range(int(2e+06)):
cmd = map(str,raw_input().split())
if cmd[0] == "insert":
q.append(int(cmd[1]))
H += 1
increase(q,H)
elif cmd[0] == "extract":
print q.popleft()
H -= 1
buildMaxHeap(q,H)
else:
break
def increase(A,i):
p = i/2
if 0 < p:
if A[p-1] < A[i-1]:
v = A[p-1]
A[p-1] = A[i-1]
A[i-1] = v
increase(A,p)
def maxHeapify(A,i,H):
l = 2*i
r = 2*i+1
if l <= H and A[l-1] > A[i-1]:
largest = l
else:
largest = i
if r <= H and A[r-1] > A[largest-1]:
largest = r
if largest != i:
v = A[i-1]
A[i-1] = A[largest-1]
A[largest-1] = v
maxHeapify(A,largest,H)
def buildMaxHeap(A,H):
for j in range(H/2):
i = H/2-j
maxHeapify(A,i)
if __name__ == "__main__":
main() | File "/tmp/tmpwseqbk6n/tmpq6w946xc.py", line 13
print q.popleft()
^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
| |
s572494384 | p02289 | u616085665 | 1500707541 | Python | Python | py | Runtime Error | 0 | 0 | 329 | def main():
q = []
while(True):
cmd = map(str,raw_input().split())
if cmd[0] == "insert":
q.append()=int(cmd[1])
elif cmd[0] == "extract":
ret = max(q)
print ret
q.remove(ret)
else:
break
if __name__ == "__main__":
main() | File "/tmp/tmp25lbmt7p/tmp2kjvj_fe.py", line 6
q.append()=int(cmd[1])
^^^^^^^^^^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
| |
s107432913 | p02289 | u024715419 | 1510120413 | Python | Python3 | py | Runtime Error | 0 | 0 | 177 | a = []
while True:
inp = input()
if inp[0] == "i":
a.append(int(inp[7:]))
elif inp[0] == "e":
a.sort()
print(a.pop())
else:
break | Traceback (most recent call last):
File "/tmp/tmp8x5_m_kr/tmpzh5ytcys.py", line 3, in <module>
inp = input()
^^^^^^^
EOFError: EOF when reading a line
| |
s003647558 | p02289 | u662418022 | 1517738189 | Python | Python3 | py | Runtime Error | 0 | 0 | 1490 | # -*- coding: utf-8 -*-
def parent(i):
return i // 2
def left(i):
return 2 * i
def right(i):
return 2 * i + 1
class MaxHeap(list):
def __init__(self, H=0):
list.__init__(self)
self.H = H
self[:] = [None] * (H+1)
def insert(self, key):
self.H += 1
self.append(-float("inf"))
self.heapIncreaseKey(self.H, key)
def heapIncreaseKey(self, i, key):
if key < self[i]:
raise "error"
self[i] = key
while i > 1 and self[parent(i)] < self[i]:
self[i], self[parent(i)] = self[parent(i)], self[i]
def heapExtract(self):
if self.H < 1:
raise "underflow"
maximum = self[1]
self[1] = A[self.H]
self.H -= 1
self.maxHeapify(1)
return maximum
def maxHeapify(self, i):
l = left(i)
r = right(i)
if l <= self.H and self[l] > self[i]:
largest = l
else:
largest = i
if r <= self.H and self[r] > self[largest]:
largest = r
if largest != i:
self[i], self[largest] = self[largest], self[i]
self.maxHeapify(largest)
if __name__ == '__main__':
A = MaxHeap()
c = [None, None]
while c[0] != "end":
c = input().split(" ")
if c[0] == "insert":
A.insert(int(c[1]))
elif c[0] == "extract":
print(A.heapExtract())
else:
pass
| Traceback (most recent call last):
File "/tmp/tmpaqbfcpat/tmpfo6v1our.py", line 64, in <module>
c = input().split(" ")
^^^^^^^
EOFError: EOF when reading a line
| |
s376060139 | p02289 | u426534722 | 1518447436 | Python | Python3 | py | Runtime Error | 0 | 0 | 781 | def maxHeapify(A, i, n):
l = i * 2 + 1
r = i * 2 + 2
if l < n and A[l] > A[i]:
largest = l
else:
largest = i
if r < n and A[r] > A[largest]:
largest = r
if largest != i:
A[i], A[largest] = A[largest], A[i]
maxHeapify(A, largest)
def insert(S, k):
S.append(k)
n = len(S)
i = n - 1
while i > 0 and S[i] > S[(i - 1) // 2]:
S[i], S[(i - 1) // 2] = S[(i - 1) // 2], S[i]
i = (i - 1) // 2
def extractMax(S):
if len(S) == 1:
return S.pop()
ans = S[0]
S[0] = S.pop()
maxHeapify(S, 0, len(S))
return ans
A = []
while True:
s = input()
if s == "end":
break
elif s == "extract":
print(extractMax(A))
else:
insert(A, int(s[7:]))
| Traceback (most recent call last):
File "/tmp/tmp7hhshokj/tmp8zd24j7z.py", line 29, in <module>
s = input()
^^^^^^^
EOFError: EOF when reading a line
| |
s155263126 | p02289 | u150984829 | 1519622530 | Python | Python3 | py | Runtime Error | 0 | 0 | 408 | def h(i):
l=2*i;r=l+1
if r<H:
if A[i]<A[l]:
if A[l]<A[r]:A[i],A[r]=A[r],A[i];h(r)
else:A[i],A[l]=A[l],A[i];h(l)
elif A[i]<A[r]:A[i],A[r]=A[r],A[i];h(r)
elif l<H and A[i]<A[l]:A[i],A[l]=A[l],A[i];h(l)
H=0
A=[0]
for a in iter(input,'end'):
if a[0]=='i':
H+=1;A+=[int(a[7:])];k=H
while k>1 and A[k//2]<A[k]:A[k],A[k//2]=A[k//2],A[k];k/=2
else:
print(A[1])
if H-1:A[1]=A.pop()
H-=1;h(1)
| Traceback (most recent call last):
File "/tmp/tmpf5gquj94/tmplrsae74i.py", line 11, in <module>
for a in iter(input,'end'):
EOFError: EOF when reading a line
| |
s730710765 | p02289 | u150984829 | 1519625234 | Python | Python3 | py | Runtime Error | 0 | 0 | 149 | import sys
from heapq import *
H,O=[],''
for e in sys.stdin:
if'i'==e[0]:heappush(H,-int(e[7:]))
elif't'==e[2]:O+=f'{-heappop(H)}\n')
print(O[-1])
| File "/tmp/tmp_hah2ta5/tmphxnt4kch.py", line 6
elif't'==e[2]:O+=f'{-heappop(H)}\n')
^
SyntaxError: unmatched ')'
| |
s135724706 | p02289 | u150984829 | 1519625791 | Python | Python3 | py | Runtime Error | 0 | 0 | 161 | import sys
from heapq import *
H,O=[],[]
for e in sys.stdin:
t=e[1]
if'n'==t:heappush(H,-int(e[7:]))
elif'x'==t:O+=[-heappop(H)]
print('\n'.join(map(str,O)))
| ||
s674250930 | p02289 | u150984829 | 1519625848 | Python | Python3 | py | Runtime Error | 0 | 0 | 161 | import sys
from heapq import *
H,O=[],[]
for e in sys.stdin:
c=e[1]
if'n'==c:heappush(H,-int(e[7:]))
elif'x'==c:O+=[-heappop(H)]
print('\n'.join(map(str,O)))
| ||
s138561262 | p02289 | u126478680 | 1525855936 | Python | Python3 | py | Runtime Error | 0 | 0 | 1679 | class PriorityQueue():
def __init__(self):
self.heap = []
self.num_node = 0
def max_heapify(self, i):
l = (i+1)*2-1
r = (i+1)*2
largest = i
if l < self.num_node and self.heap[l] > self.heap[i]:
largest = l
else:
largest = i
if r < self.num_node and self.heap[r] > self.heap[largest]:
largest = r
if largest != i:
self.heap[i], self.heap[largest] = self.heap[largest], self.heap[i]
self.max_heapify(largest)
def exchange(self, i):
l = (i+1)*2-1
r = (i+1)*2
largest = i
if l < self.num_node and self.heap[l] > self.heap[i]:
largest = l
else:
largest = i
if r < self.num_node and self.heap[r] > self.heap[largest]:
largest = r
if largest != i:
self.heap[i], self.heap[largest] = self.heap[largest], self.heap[i]
def insert(self, k):
self.heap.append(k)
i = int((self.num_node-1)/2)
self.num_node += 1
while i != 0:2
self.exchange(i)
i = int(i/2)
self.max_heapify(i)
def extract_max(self):
if self.num_node == 1:
self.num_node = 0
return self.heap.pop()
max_val = self.heap[0]
self.heap[0] = self.heap.pop()
self.num_node -= 1
self.max_heapify(0)
return max_val
pq = PriorityQueue()
while True:
op = input()
if op == 'end': break
if op == 'extract':
print(pq.extract_max())
else:
ope, num = op.split(' ')
num = int(num)
pq.insert(num)
| File "/tmp/tmpwti5o9f9/tmpmgh6m8tm.py", line 40
self.exchange(i)
IndentationError: unexpected indent
| |
s245387382 | p02289 | u126478680 | 1525855995 | Python | Python3 | py | Runtime Error | 0 | 0 | 1679 | class PriorityQueue():
def __init__(self):
self.heap = []
self.num_node = 0
def max_heapify(self, i):
l = (i+1)*2-1
r = (i+1)*2
largest = i
if l < self.num_node and self.heap[l] > self.heap[i]:
largest = l
else:
largest = i
if r < self.num_node and self.heap[r] > self.heap[largest]:
largest = r
if largest != i:
self.heap[i], self.heap[largest] = self.heap[largest], self.heap[i]
self.max_heapify(largest)
def exchange(self, i):
l = (i+1)*2-1
r = (i+1)*2
largest = i
if l < self.num_node and self.heap[l] > self.heap[i]:
largest = l
else:
largest = i
if r < self.num_node and self.heap[r] > self.heap[largest]:
largest = r
if largest != i:
self.heap[i], self.heap[largest] = self.heap[largest], self.heap[i]
def insert(self, k):
self.heap.append(k)
i = int((self.num_node-1)/2)
self.num_node += 1
while i != 0:2
self.exchange(i)
i = int(i/2)
self.max_heapify(i)
def extract_max(self):
if self.num_node == 1:
self.num_node = 0
return self.heap.pop()
max_val = self.heap[0]
self.heap[0] = self.heap.pop()
self.num_node -= 1
self.max_heapify(0)
return max_val
pq = PriorityQueue()
while True:
op = input()
if op == 'end': break
if op == 'extract':
print(pq.extract_max())
else:
ope, num = op.split(' ')
num = int(num)
pq.insert(num)
| File "/tmp/tmpjef0w88i/tmpv0ggveob.py", line 40
self.exchange(i)
IndentationError: unexpected indent
| |
s040756571 | p02289 | u269391636 | 1526898206 | Python | Python3 | py | Runtime Error | 0 | 0 | 170 | a = []
while(True):
x = input().split()
if x[0] == "end":
quit()
elif x[0] == "insert":
a.append(x[1])
a.sort(reversed = True)
else:
print(a[0])
del(a[0])
| Traceback (most recent call last):
File "/tmp/tmpnnoc63i5/tmpdixekchs.py", line 3, in <module>
x = input().split()
^^^^^^^
EOFError: EOF when reading a line
| |
s549721304 | p02289 | u684241248 | 1528521521 | Python | Python3 | py | Runtime Error | 0 | 0 | 1315 | # -*- coding: utf-8 -*-
INF = -10**10
queue = [-1]
def insert(queue, key):
h = len(queue) - 1
queue.append(INF)
heap_increase_key(queue, h + 1, key)
def heap_increase_key(queue, i, key):
if key < queue[i]:
raise ValueError('The new key is smaller than the present key')
queue[i] = key
while i > 1 and queue[i // 2] < queue[i]:
queue[i], queue[i // 2] = queue[i // 2], queue[i]
i = i // 2
def extract_max(queue):
h = len(queue) - 1
if h < 1:
raise TypeError('Heap underflowed')
max = queue[1]
queue[1] = queue.pop()
max_heapify(queue, 1)
return max
def max_heapify(queue, i):
h = len(queue) - 1
l = 2 * i
r = 2 * i + 1
if l <= h and queue[l] > queue[i]:
largest = l
else:
largest = i
if r <= h and queue[r] > queue[largest]:
largest = r
if largest != i:
queue[i], queue[largest] = queue[largest], queue[i]
max_heapify(queue, largest)
if __name__ == '__main__':
import sys
ords = [line.strip().split() for line in sys.stdin]
for ord in ords:
if len(ord) > 1:
ord, key = ord
if ord[0] == 'i':
insert(queue, key)
elif len(ord) == 7:
extract_max(queue)
else:
break
| ||
s976379575 | p02289 | u782850731 | 1380230153 | Python | Python | py | Runtime Error | 0 | 0 | 1409 | #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint
from array import array
MININT = -1 - maxint
def max_heapify(a, i, heap_size):
L = 2*i
R = 2*i + 1
if L <= heap_size and a[L] > a[i]:
largest = L
else:
largest = i
if R <= heap_size and a[R] > a[largest]:
largest = R
if largest != i:
a[i], a[largest] = a[largest], a[i]
max_heapify(a, largest, heap_size)
def max_heap_insert(a, key, heap_size):
heap_size[0] += 1
a[heap_size[0]] = MININT
heap_increase_key(a, key, heap_size[0])
def heap_increase_key(a, key, i):
#if key < a[i]:
#raise ValueError('new key less current key')
a[i] = key
half = i // 2
while i > 1 and a[half] < a[i]:
a[i], a[half] = a[half], a[i]
i = i // 2
half = i // 2
def heap_extract_max(a, heap_size):
#if heap_size[0] < 1:
#raise ValueError('heap under flow')
max = a[1]
a[1] = a[heap_size[0]]
heap_size[0] -= 1
max_heapify(a, 1, heap_size[0])
return max
heap = array('i', [MININT] * 2000001)
heap_size = [1]
for cmd in stdin:
if cmd[0] == 'i':
key = int(cmd[7:])
#assert 0 <= key <= 2000000000
max_heap_insert(heap, key, heap_size)
elif cmd[1] == 'x':
print(heap_extract_max(heap, heap_size))
elif cmd[1] == 'n':
break | Traceback (most recent call last):
File "/tmp/tmp66saqzsa/tmpinkvhdth.py", line 3, in <module>
from sys import stdin, maxint
ImportError: cannot import name 'maxint' from 'sys' (unknown location)
| |
s967195321 | p02290 | u540744789 | 1426163250 | Python | Python | py | Runtime Error | 20 | 4316 | 772 | x1,y1,x2,y2=map(float,raw_input().split(" "))
if y1==y2 or x1==x2:
if y1==y2:
t0=0
if x1==x2:
t1=0
else:
t0=(y2-y1)/(x2-x1)
b0=y1-t0*x1
t1=-(x2-x1)/(y2-y1)
for i in xrange(int(raw_input())):
px,py=map(float,raw_input().split(" "))
if t0==0 or t1==0:
if t0==0:
t1=-1
a=1.0
b=-t0
c=y1
d=0.0
e=-t1
f=px
if t1==0:
t0=-1
a=0.0
b=-t0
c=x1
d=1.0
e=-t0
f=py
else:
b1=py-t1*px
a,b,c,d,e,f=1.0,-t0,b0,1.0,-t1,b1
kouten_y=(c*e-f*b)/(a*e-b*d)
kouten_x=(a*f-c*d)/(a*e-b*d)
print "{0:.10f} {1:.10f}".format(kouten_x,kouten_y) | File "/tmp/tmpylmm8omb/tmpjy7wnnsh.py", line 36
print "{0:.10f} {1:.10f}".format(kouten_x,kouten_y)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
| |
s923946035 | p02290 | u988834390 | 1502884545 | Python | Python3 | py | Runtime Error | 0 | 0 | 349 |
points=[]
points=int(input().split())
p1,q1,p2,q2=points[0:3]
def search_x(x,y):
return ((q2-q1)*x+q1*((q2-q1)*(q2-q1))/(p2-p1))/((q2-q1)*(q2-q1)/(p2-p1)+(p2-p1))
n=int(input())
for i in range(n):
point=[]
point=int(input().split())
x=search_x(point[0],point[1])
y=(x-q1)*(q2-q1)/(p2-p1)-q1
print('{} {}'.format(x,y))
| Traceback (most recent call last):
File "/tmp/tmpj0i0c7ao/tmpke670xte.py", line 3, in <module>
points=int(input().split())
^^^^^^^
EOFError: EOF when reading a line
| |
s853389965 | p02290 | u988834390 | 1502884622 | Python | Python3 | py | Runtime Error | 0 | 0 | 290 |
points=[]
points=int(input().split())
p1,q1,p2,q2=points[0:3]
n=int(input())
for i in range(n):
point=[]
point=int(input().split())
x=((q2-q1)*x+q1*((q2-q1)*(q2-q1))/(p2-p1))/((q2-q1)*(q2-q1)/(p2-p1)+(p2-p1))
y=(x-q1)*(q2-q1)/(p2-p1)-q1
print('{} {}'.format(x,y))
| Traceback (most recent call last):
File "/tmp/tmpg5qqdi77/tmphx_tial_.py", line 3, in <module>
points=int(input().split())
^^^^^^^
EOFError: EOF when reading a line
| |
s290150229 | p02290 | u126478680 | 1526238441 | Python | Python3 | py | Runtime Error | 20 | 5684 | 900 | import math
class Point():
def __init__(self, x=None, y=None):
self.x = x
self.y = y
class Vector():
def __init__(self, x, y):
self.x = x
self.y = y
self.abs = math.sqrt(x*x + y*y)
def constant_multipled(self, c):
return Vector(self.x*c, self.y*c)
def inner_product(self, vec):
return self.x*vec.x + self.y*vec.y
x1, y1, x2, y2 = list(map(int, input().split(' ')))
start = Point(x1, y1)
base_vec = Vector(x2-x1, y2-y1)
q = int(input())
vectors = []
for i in range(q):
x, y = list(map(int, input().split(' ')))
vectors.append(Vector(x-start.x, y-start.y))
for vec in vectors:
cos = base_vec.inner_product(vec)/(base_vec.abs*vec.abs)
b_cos = vec.abs*cos
vec_x = base_vec.constant_multipled(b_cos/base_vec.abs)
ans_x, ans_y = vec_x.x + start.x, vec_x.y + start.y
print('%.8f'%ans_x, '%.8f'%ans_y)
| Traceback (most recent call last):
File "/tmp/tmpk72vrxge/tmp9_kpckwl.py", line 20, in <module>
x1, y1, x2, y2 = list(map(int, input().split(' ')))
^^^^^^^
EOFError: EOF when reading a line
| |
s030926130 | p02290 | u572424947 | 1376578382 | Python | Python | py | Runtime Error | 10 | 4296 | 725 | class Point():
def __init__(self, x, y):
self.x = x
self.y = y
output_list = []
init_point = map(float, raw_input().split())
p0 = Point(init_point[0], init_point[1])
p1 = Point(init_point[2], init_point[3])
q = int(raw_input())
datalist = [map(float, raw_input().split()) for i in range(q)]
#p0--p1 : y=ax+b
#p2--t : y=cx+d
a = (p0.y - p1.y) / (p0.x - p1.x)
if a != 0:
c = -1/a
b = p0.y - a*p0.x
for data in datalist:
p2 = Point(data[0], data[1])
d = p2.y - c*p2.x
X = (-b+d) / (a-c)
Y = a*X + b
output_list.append( (X,Y) )
else:
for data in datalist:
p2 = Point(data[0], data[1])
output_list.append( (p2.x, p0.y) )
for x, y in output_list:
print "%.10f %.10f" % (x, y)
| File "/tmp/tmpue3hgqui/tmppj7ypvuo.py", line 45
print "%.10f %.10f" % (x, y)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
| |
s355148711 | p02291 | u988834390 | 1502885083 | Python | Python3 | py | Runtime Error | 0 | 0 | 721 | """
p1p2: (y-y1)(x2-x1)=(x-x1)(y2-y1)
p vertical: (y2-y1)(y-py)+(x2-x1)(x-px)=0
y=(x-x1)(y2-y1)/(x2-x1)-y1
(y2-y1)((x-x1)(y2-y1)/(x2-x1)-y1-py)+(x2-x1)(x-px)=0
(x-x1)(y2-y1)^2/(x2-x1)+(y2-y1)(y1+py)+(x2-x1)x-(x2-x1)px=0
x((y2-y1)^2/(x2-x1)+(x2-x1))-x1((y2-y1)^2/(x2-x1)-(x2-x1)px=0
x=((x2-x1)px+x1((y2-y1)^2/(x2-x1))/((y2-y1)^2/(x2-x1)+(x2-x1))
"""
points=[]
points=int(input().split())
p1,q1,p2,q2=points[0:3]
def search_x(x,y):
return ((q2-q1)*x+q1*((q2-q1)*(q2-q1))/(p2-p1))/((q2-q1)*(q2-q1)/(p2-p1)+(p2-p1))
n=int(input())
for i in range(n):
point=[]
point=int(input().split())
x=search_x(point[0],point[1])
y=(x-q1)*(q2-q1)/(p2-p1)-q1
print('{} {}'.format(x,y)) | Traceback (most recent call last):
File "/tmp/tmp8gk1uxq3/tmp83nmv_v_.py", line 12, in <module>
points=int(input().split())
^^^^^^^
EOFError: EOF when reading a line
| |
s217160128 | p02291 | u548155360 | 1529920481 | Python | Python3 | py | Runtime Error | 0 | 0 | 1078 | # coding=utf-8
import numpy as np
from math import sqrt
def vector_abs(vect):
return sqrt(sum([element**2 for element in vect]))
def direction_unit_vector(p_from, p_to):
d_vector = p_to - p_from
d_u_vector = d_vector/vector_abs(d_vector)
return d_u_vector
def projection(origin, line_from, line_to):
direction_unit = direction_unit_vector(line_from, line_to)
origin_d_vector = origin - line_from
inject_dist = np.inner(direction_unit, origin_d_vector)
on_line_vect = inject_dist*direction_unit
return on_line_vect + line_from
def reflection(origin, line_from, line_to):
mid_point = projection(origin, line_from, line_to)
reflected = origin + 2 * (mid_point - origin)
return reflected
if __name__ == '__main__':
xy_list = np.array(list(map(int, input().split())))
p1_list = xy_list[:2]
p2_list = xy_list[2:]
Q = int(input())
for i in range(Q):
p_list = np.array(list(map(int, input().split())))
x_list = reflection(p_list, p1_list, p2_list)
print(' '.join(map(str, x_list)))
| Traceback (most recent call last):
File "/tmp/tmpjm9ur9ng/tmpnazmfnyw.py", line 31, in <module>
xy_list = np.array(list(map(int, input().split())))
^^^^^^^
EOFError: EOF when reading a line
| |
s243349467 | p02291 | u548155360 | 1529921156 | Python | Python3 | py | Runtime Error | 0 | 0 | 1419 | # coding=utf-8
from math import sqrt, fsum
def inner_product(vect1, vect2):
return math.fsum([(v1_el*v2_el) for v1_el, v2_el in zip(vect1, vect2)])
def vector_abs(vect):
return sqrt(sum([element**2 for element in vect]))
def direction_unit_vector(p_from, p_to):
d_vector = [(xt - xf) for xt, xf in zip(p_to, p_from)]
d_u_vector = [element/vector_abs(d_vector) for element in d_vector]
return d_u_vector
def projection(origin, line_from, line_to):
direction_unit = direction_unit_vector(line_from, line_to)
origin_d_vector = [(org-lf) for org, lf in zip(origin, line_from)]
inject_dist = inner_product(direction_unit, origin_d_vector)
on_line_vect = [inject_dist*element for element in direction_unit]
return [olv_el + lf_el for olv_el, lf_el in zip(on_line_vect, line_from)]
def reflection(origin, line_from, line_to):
mid_point = projection(origin, line_from, line_to)
direction = [2*(mp_el - or_el) for mp_el, or_el in zip(mid_point, origin)]
reflected = [(dr_el + or_el) for dr_el, or_el in zip(direction, origin)]
return reflected
if __name__ == '__main__':
xy_list = list(map(int, input().split()))
p1_list = xy_list[:2]
p2_list = xy_list[2:]
Q = int(input())
for i in range(Q):
p_list = list(map(int, input().split()))
x_list = reflection(p_list, p1_list, p2_list)
print(' '.join(map(str, x_list)))
| Traceback (most recent call last):
File "/tmp/tmpieen2igv/tmpn9g4a1od.py", line 35, in <module>
xy_list = list(map(int, input().split()))
^^^^^^^
EOFError: EOF when reading a line
| |
s683041859 | p02292 | u487861672 | 1551589956 | Python | Python3 | py | Runtime Error | 60 | 7300 | 6212 | #! /usr/bin/env python3
from typing import List, Tuple
from math import sqrt
from enum import Enum
EPS = 1e-10
def float_equal(x: float, y: float) -> bool:
return abs(x - y) < EPS
class PointLocation(Enum):
COUNTER_CLOCKWISE = 1
CLOCKWISE = 2
ONLINE_BACK = 3
ONLINE_FRONT = 4
ON_SEGMENT = 5
class Point:
def __init__(self, x: float=0.0, y: float=0.0) -> None:
self.x = x
self.y = y
def __repr__(self) -> str:
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other: object) -> bool:
if not isinstance(other, Point):
# print("NotImplemented in Point")
return NotImplemented
return float_equal(self.x, other.x) and \
float_equal(self.y, other.y)
def __add__(self, other: 'Point') -> 'Point':
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other: 'Point') -> 'Point':
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, k: float) -> 'Point':
return Point(self.x * k, self.y * k)
def __rmul__(self, k: float) -> 'Point':
return self * k
def __truediv__(self, k: float) -> 'Point':
return Point(self.x / k, self.y / k)
def __lt__(self, other: 'Point') -> bool:
return self.y < other.y \
if abs(self.x - other.x) < EPS \
else self.x < other.x
def norm(self):
return self.x * self.x + self.y * self.y
def abs(self):
return sqrt(self.norm())
def dot(self, other: 'Point') -> float:
return self.x * other.x + self.y * other.y
def cross(self, other: 'Point') -> float:
return self.x * other.y - self.y * other.x
def is_orthogonal(self, other: 'Point') -> bool:
return float_equal(self.dot(other), 0.0)
def is_parallel(self, other: 'Point') -> bool:
return float_equal(self.cross(other), 0.0)
def distance(self, other: 'Point') -> float:
return (self - other).abs()
def in_side_of(self, seg: 'Segment') -> bool:
return seg.vector().dot(
Segment(seg.p1, self).vector()) >= 0
def in_width_of(self, seg: 'Segment') -> bool:
return \
self.in_side_of(seg) and \
self.in_side_of(seg.reverse())
def distance_to_line(self, seg: 'Segment') -> float:
return \
abs((self - seg.p1).cross(seg.vector())) / \
seg.length()
def distance_to_segment(self, seg: 'Segment') -> float:
if not self.in_side_of(seg):
return self.distance(seg.p1)
if not self.in_side_of(seg.reverse()):
return self.distance(seg.p2)
else:
return self.distance_to_line(seg)
def location(self, seg: 'Segment') -> PointLocation:
p = self - seg.p1
d = seg.vector().cross(p)
if d < 0:
return PointLocation.CLOCKWISE
elif d > 0:
return PointLocation.COUNTER_CLOCKWISE
else:
r = (self.x - seg.p1.x) / (seg.p2.x - seg.p1.x)
if r < 0:
return PointLocation.ONLINE_BACK
elif r > 1:
return PointLocation.ONLINE__FRONT
else:
return PointLocation.ON_SEGMENT
Vector = Point
class Segment:
def __init__(self, p1: Point = None, p2: Point = None) -> None:
self.p1: Point = Point() if p1 is None else p1
self.p2: Point = Point() if p2 is None else p2
def __repr__(self) -> str:
return "Segment({}, {})".format(self.p1, self.p2)
def __eq__(self, other: object) -> bool:
if not isinstance(other, Segment):
# print("NotImplemented in Segment")
return NotImplemented
return self.p1 == other.p1 and self.p2 == other.p2
def vector(self) -> Vector:
return self.p2 - self.p1
def reverse(self) -> 'Segment':
return Segment(self.p2, self.p1)
def length(self) -> float:
return self.p1.distance(self.p2)
def is_orthogonal(self, other: 'Segment') -> bool:
return self.vector().is_orthogonal(other.vector())
def is_parallel(self, other: 'Segment') -> bool:
return self.vector().is_parallel(other.vector())
def projection(self, p: Point) -> Point:
v = self.vector()
vp = p - self.p1
return v.dot(vp) / v.norm() * v + self.p1
def reflection(self, p: Point) -> Point:
x = self.projection(p)
return p + 2 * (x - p)
def intersect_ratio(self, other: 'Segment') -> Tuple[float, float]:
a = self.vector()
b = other.vector()
c = self.p1 - other.p1
s = b.cross(c) / a.cross(b)
t = a.cross(c) / a.cross(b)
return s, t
def intersects(self, other: 'Segment') -> bool:
s, t = self.intersect_ratio(other)
return (0 <= s <= 1) and (0 <= t <= 1)
def intersection(self, other: 'Segment') -> Point:
s, _ = self.intersect_ratio(other)
return self.p1 + s * self.vector()
def distance_with_segment(self, other: 'Segment') -> float:
if not self.is_parallel(other) and \
self.intersects(other):
return 0
else:
return min(
self.p1.distance_to_segment(other),
self.p2.distance_to_segment(other),
other.p1.distance_to_segment(self),
other.p2.distance_to_segment(self))
Line = Segment
class Circle:
def __init__(self, c: Point=None, r: float=0.0) -> None:
self.c: Point = Point() if c is None else c
self.r: float = r
def __eq__(self, other: object) -> bool:
if not isinstance(other, Circle):
return NotImplemented
return self.c == other.c and self.r == other.r
def __repr__(self) -> str:
return "Circle({}, {})".format(self.c, self.r)
def main() -> None:
x0, y0, x1, y1 = [int(x) for x in input().split()]
s = Segment(Point(x0, y0), Point(x1, y1))
q = int(input())
for _ in range(q):
x2, y2 = [int(x) for x in input().split()]
print(Point(x2, y2).location(s).name)
if __name__ == "__main__":
main()
| Traceback (most recent call last):
File "/tmp/tmpj8fix9wd/tmpi3m_6u32.py", line 216, in <module>
main()
File "/tmp/tmpj8fix9wd/tmpi3m_6u32.py", line 206, in main
x0, y0, x1, y1 = [int(x) for x in input().split()]
^^^^^^^
EOFError: EOF when reading a line
| |
s810354808 | p02292 | u487861672 | 1551590028 | Python | Python3 | py | Runtime Error | 60 | 7304 | 6211 | #! /usr/bin/env python3
from typing import List, Tuple
from math import sqrt
from enum import Enum
EPS = 1e-10
def float_equal(x: float, y: float) -> bool:
return abs(x - y) < EPS
class PointLocation(Enum):
COUNTER_CLOCKWISE = 1
CLOCKWISE = 2
ONLINE_BACK = 3
ONLINE_FRONT = 4
ON_SEGMENT = 5
class Point:
def __init__(self, x: float=0.0, y: float=0.0) -> None:
self.x = x
self.y = y
def __repr__(self) -> str:
return "Point({}, {})".format(self.x, self.y)
def __eq__(self, other: object) -> bool:
if not isinstance(other, Point):
# print("NotImplemented in Point")
return NotImplemented
return float_equal(self.x, other.x) and \
float_equal(self.y, other.y)
def __add__(self, other: 'Point') -> 'Point':
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other: 'Point') -> 'Point':
return Point(self.x - other.x, self.y - other.y)
def __mul__(self, k: float) -> 'Point':
return Point(self.x * k, self.y * k)
def __rmul__(self, k: float) -> 'Point':
return self * k
def __truediv__(self, k: float) -> 'Point':
return Point(self.x / k, self.y / k)
def __lt__(self, other: 'Point') -> bool:
return self.y < other.y \
if abs(self.x - other.x) < EPS \
else self.x < other.x
def norm(self):
return self.x * self.x + self.y * self.y
def abs(self):
return sqrt(self.norm())
def dot(self, other: 'Point') -> float:
return self.x * other.x + self.y * other.y
def cross(self, other: 'Point') -> float:
return self.x * other.y - self.y * other.x
def is_orthogonal(self, other: 'Point') -> bool:
return float_equal(self.dot(other), 0.0)
def is_parallel(self, other: 'Point') -> bool:
return float_equal(self.cross(other), 0.0)
def distance(self, other: 'Point') -> float:
return (self - other).abs()
def in_side_of(self, seg: 'Segment') -> bool:
return seg.vector().dot(
Segment(seg.p1, self).vector()) >= 0
def in_width_of(self, seg: 'Segment') -> bool:
return \
self.in_side_of(seg) and \
self.in_side_of(seg.reverse())
def distance_to_line(self, seg: 'Segment') -> float:
return \
abs((self - seg.p1).cross(seg.vector())) / \
seg.length()
def distance_to_segment(self, seg: 'Segment') -> float:
if not self.in_side_of(seg):
return self.distance(seg.p1)
if not self.in_side_of(seg.reverse()):
return self.distance(seg.p2)
else:
return self.distance_to_line(seg)
def location(self, seg: 'Segment') -> PointLocation:
p = self - seg.p1
d = seg.vector().cross(p)
if d < 0:
return PointLocation.CLOCKWISE
elif d > 0:
return PointLocation.COUNTER_CLOCKWISE
else:
r = (self.x - seg.p1.x) / (seg.p2.x - seg.p1.x)
if r < 0:
return PointLocation.ONLINE_BACK
elif r > 1:
return PointLocation.ONLINE_FRONT
else:
return PointLocation.ON_SEGMENT
Vector = Point
class Segment:
def __init__(self, p1: Point = None, p2: Point = None) -> None:
self.p1: Point = Point() if p1 is None else p1
self.p2: Point = Point() if p2 is None else p2
def __repr__(self) -> str:
return "Segment({}, {})".format(self.p1, self.p2)
def __eq__(self, other: object) -> bool:
if not isinstance(other, Segment):
# print("NotImplemented in Segment")
return NotImplemented
return self.p1 == other.p1 and self.p2 == other.p2
def vector(self) -> Vector:
return self.p2 - self.p1
def reverse(self) -> 'Segment':
return Segment(self.p2, self.p1)
def length(self) -> float:
return self.p1.distance(self.p2)
def is_orthogonal(self, other: 'Segment') -> bool:
return self.vector().is_orthogonal(other.vector())
def is_parallel(self, other: 'Segment') -> bool:
return self.vector().is_parallel(other.vector())
def projection(self, p: Point) -> Point:
v = self.vector()
vp = p - self.p1
return v.dot(vp) / v.norm() * v + self.p1
def reflection(self, p: Point) -> Point:
x = self.projection(p)
return p + 2 * (x - p)
def intersect_ratio(self, other: 'Segment') -> Tuple[float, float]:
a = self.vector()
b = other.vector()
c = self.p1 - other.p1
s = b.cross(c) / a.cross(b)
t = a.cross(c) / a.cross(b)
return s, t
def intersects(self, other: 'Segment') -> bool:
s, t = self.intersect_ratio(other)
return (0 <= s <= 1) and (0 <= t <= 1)
def intersection(self, other: 'Segment') -> Point:
s, _ = self.intersect_ratio(other)
return self.p1 + s * self.vector()
def distance_with_segment(self, other: 'Segment') -> float:
if not self.is_parallel(other) and \
self.intersects(other):
return 0
else:
return min(
self.p1.distance_to_segment(other),
self.p2.distance_to_segment(other),
other.p1.distance_to_segment(self),
other.p2.distance_to_segment(self))
Line = Segment
class Circle:
def __init__(self, c: Point=None, r: float=0.0) -> None:
self.c: Point = Point() if c is None else c
self.r: float = r
def __eq__(self, other: object) -> bool:
if not isinstance(other, Circle):
return NotImplemented
return self.c == other.c and self.r == other.r
def __repr__(self) -> str:
return "Circle({}, {})".format(self.c, self.r)
def main() -> None:
x0, y0, x1, y1 = [int(x) for x in input().split()]
s = Segment(Point(x0, y0), Point(x1, y1))
q = int(input())
for _ in range(q):
x2, y2 = [int(x) for x in input().split()]
print(Point(x2, y2).location(s).name)
if __name__ == "__main__":
main()
| Traceback (most recent call last):
File "/tmp/tmp293htxvr/tmpdrmj3wa8.py", line 216, in <module>
main()
File "/tmp/tmp293htxvr/tmpdrmj3wa8.py", line 206, in main
x0, y0, x1, y1 = [int(x) for x in input().split()]
^^^^^^^
EOFError: EOF when reading a line
| |
s263924425 | p02292 | u548155360 | 1529922589 | Python | Python3 | py | Runtime Error | 20 | 5616 | 1249 | # coding=utf-8
def cross_product(vect1, vect2):
return vect1[0]*vect2[1] - vect1[1]*vect2[0]
def vector_plus(vect1, vect2):
return [el1 + el2 for el1, el2 in zip(vect1, vect2)]
def vector_minus(vect1, vect2):
return [el1 - el2 for el1, el2 in zip(vect1, vect2)]
def vector_product(vect1, vect2):
return [el1 * el2 for el1, el2 in zip(vect1, vect2)]
def vector_divide(vect1, vect2):
return [el1 / el2 for el1, el2 in zip(vect1, vect2)]
def which_place(origin, line_to1, line_to2):
line1 = vector_minus(line_to1, origin)
line2 = vector_minus(line_to2, origin)
judge = cross_product(line1, line2)
if judge > 0:
return "COUNTER_CLOCKWISE"
if judge < 0:
return "CLOCKWISE"
if judge == 0:
judge2 = line2[0]/line1[0]
if judge2 < 0:
return "ONLINE_BACK"
if judge2 > 1:
return "ONLINE_FRONT"
else:
return "ON_SEGMENT"
if __name__ == '__main__':
xy_list = list(map(int, input().split()))
p0_list = xy_list[:2]
p1_list = xy_list[2:]
Q = int(input())
for i in range(Q):
p2_list = list(map(int, input().split()))
place = which_place(p0_list, p1_list, p2_list)
print(place)
| Traceback (most recent call last):
File "/tmp/tmp17bxr1uc/tmpzvisg8gg.py", line 44, in <module>
xy_list = list(map(int, input().split()))
^^^^^^^
EOFError: EOF when reading a line
| |
s632504868 | p02293 | u711765449 | 1485351517 | Python | Python3 | py | Runtime Error | 0 | 0 | 836 | n = int(input())
for i in range(n):
x0,y0,x1,y1,x2,y2,x3,y3 = map(float,input().split())
if x1 - x0 == 0:
if x3 -x2 == 0:
print('2')
elif y3 - y2 == 0:
print('1')
else:
print('0')
elif x3 - x2 == 0:
if y1 - y0 == 0:
print('1')
else:
print('0')
elif y1 - y0 == 0:
if y3 - y2 == 0:
print('2')
elif x3 - x2 == 0:
print('1')
else:
print('0')
elif y3 - y2 == 0:
elif x1 - x0 == 0:
print('1')
else:
print('0')
else:
a1 = (y1-y0)/(x1-x0)
a2 = (y3-y2)/(x3-x2)
if a1 * a2 == -1:
print('1')
elif a1 == a2 or a1 == -a2:
print('2')
else:
print('0') | File "/tmp/tmpct0ejc52/tmpndnd48qs.py", line 24
elif x1 - x0 == 0:
^^^^
SyntaxError: invalid syntax
| |
s378277471 | p02293 | u988834390 | 1502886500 | Python | Python3 | py | Runtime Error | 0 | 0 | 277 |
points=[]
n=int(input())
points=input().split()
p0,q0,p1,q1,p2,q2,p3,q3=points
for i in range(n):
if (q1 - q0) * (p2 - p3) == (q2 - q3) * (p1 - p0):
print(2)
elif (q1 - q0) * (q2 - q3) + (p1 - p0) * (p2 - p3) == 1:
print(1)
else:
print(0) | Traceback (most recent call last):
File "/tmp/tmpqqs_f8rl/tmpukudp8eh.py", line 3, in <module>
n=int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s688728991 | p02294 | u279605379 | 1503550641 | Python | Python3 | py | Runtime Error | 0 | 0 | 1054 | class Line:
def __init__(self,p1,p2):
if p1[1] < p2[1]:self.s=p2;self.e=p1
elif p1[1] > p2[1]:self.s=p1;self.e=p2
else:
if p1[0] < p2[0]:self.s=p1;self.e=p2
else:self.s=p2;self.e=p1
def dot(a,b):return a[0]*b[0] + a[1]*b[1]
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dif(a,b):return [x-y for x,y in zip(a,b)]
def InterSection(l,m):
a = dif(l.e,l.s);b = dif(m.e,l.s);c = dif(m.s,l.s)
d = dif(m.e,m.s);e = dif(l.e,m.s);f = dif(l.s,m.s)
g = lambda a, b : cross(a,b)==0 and dot(a,b)>0 and dot(b,b)<dot(a,a)
if g(a,b) or g(a,c) or g(d,e) or g(d,f):return True
elif l.s == m.e or l.s == m.s or l.e == m.e or l.e == m.s:return True
elif cross(a,b) * cross(a,c) >= 0 or cross(d,e) * cross(d,f) >= 0:return False
else:return True
q = int(input())
for i in range(q):
x0,y0,x1,y1,x2,y2,x3,y3 = [int(i) for i in input().split()]
a = [x0,y0] ; b = [x1,y1] ; c = [x2,y2] ; d = [x3,y3]
l1 = Line(b,1) ; l2 = Line(b,1)
if InterSection(l1,l2):print(1)
else:print(0) | Traceback (most recent call last):
File "/tmp/tmpohvzgcox/tmp4hovycyq.py", line 20, in <module>
q = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s558557702 | p02294 | u126478680 | 1527475610 | Python | Python3 | py | Runtime Error | 20 | 5672 | 1351 | import math
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
class Segment():
def __init__(self, x1, y1, x2, y2):
self.p1 = Point(x1, y1)
self.p2 = Point(x2, y2)
self.slope = None
self.intersept = None
if self.p1.x == self.p2.x:
self.slope = float('inf')
else:
self.slope = (self.p2.y - self.p1.y)/(self.p2.x - self.p1.x)
self.intersept = self.p1.y - self.slope*self.p1.x
def is_in_range(self, x, y):
return ((x - self.p1.x)*(x - self.p2.x) <= 0 and (y - self.p1.y)*(y - self.p2.y) <= 0)
def is_intersect(self, seg):
if self.slope == seg.slope: return False
slope_diff = seg.slope - self.slope
if self.slope == float('inf'):
x = self.p1.x
elif seg.slope == float('inf'):
x = seg.p1.x
else:
x = -(seg.intersept - self.intersept)/slope_diff
y = self.slope * x + self.intersept
if seg.is_in_range(x, y) and self.is_in_range(x, y): return True
return False
q = int(input())
for i in range(q):
x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split(' ')))
line1, line2 = Segment(x0, y0, x1, y1), Segment(x2, y2, x3, y3)
if line1.is_intersect(line2):
print(1)
else:
print(0)
| Traceback (most recent call last):
File "/tmp/tmptzf37tl7/tmp2rlts2wz.py", line 37, in <module>
q = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s443355786 | p02296 | u022407960 | 1480593150 | Python | Python3 | py | Runtime Error | 0 | 0 | 1421 | # !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4 5 1
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2
output:
INF
0
-5
-3
OR
input:
4 6 0
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2
3 1 0
output:
NEGATIVE CYCLE
"""
import sys
from math import isinf
def generate_adj_table(_v_info):
for each in _v_info:
source, target, cost = map(int, each)
init_adj_table[source][target] = cost
return init_adj_table
def bellman_ford():
distance[root] = 0
for j in range(vertices - 1):
for current, current_info in enumerate(adj_table):
for adj, cost in current_info.items():
if distance[current] + cost < distance[adj]:
distance[adj] = distance[current] + cost
for current, current_info in enumerate(adj_table):
for adj, cost in current_info.items():
if distance[current] + cost < distance[adj]:
print('NEGATIVE CYCLE')
return list()
return distance
if __name__ == '__main__':
_input = sys.stdin.readlines()
vertices, edges, root = map(int, _input[0].split())
v_info = map(lambda x: x.split(), _input[1:])
distance = [float('inf')] * vertices
init_adj_table = tuple(dict() for _ in range(vertices))
adj_table = generate_adj_table(v_info)
res = bellman_ford()
for ele in res:
if isinf(ele):
print('INF')
else:
print(ele) | Traceback (most recent call last):
File "/tmp/tmpklinmrc1/tmplpbstd6r.py", line 64, in <module>
vertices, edges, root = map(int, _input[0].split())
~~~~~~^^^
IndexError: list index out of range
| |
s497723373 | p02296 | u279605379 | 1503627679 | Python | Python3 | py | Runtime Error | 0 | 0 | 2163 | class Line:
def __init__(self,p1,p2):
if p1[1] < p2[1]:self.s=p2;self.e=p1
elif p1[1] > p2[1]:self.s=p1;self.e=p2
else:
if p1[0] < p2[0]:self.s=p1;self.e=p2
else:self.s=p2;self.e=p1
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dot(a,b):return a[0]*b[0]+a[1]*b[1]
def dif(a,b):return [x-y for x,y in zip(a,b)]
def dist(a,b):return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
def isec(l,m):
a = dif(l.e,l.s);b = dif(m.e,l.s);c = dif(m.s,l.s)
d = dif(m.e,m.s);e = dif(l.e,m.s);f = dif(l.s,m.s)
g = lambda a, b : cross(a,b)==0 and dot(a,b)>0 and dot(b,b)<dot(a,a)
if g(a,b) or g(a,c) or g(d,e) or g(d,f):return True
elif l.s == m.e or l.s == m.s or l.e == m.e or l.e == m.s:return True
elif cross(a,b) * cross(a,c) >= 0 or cross(d,e) * cross(d,f) >= 0:return False
else:return True
def projection(a,b):return [x*dot(a,b)/dot(a,a) for x in a]
def proj(A,B,C,D):
AB = dif(B,A) ; AC = dif(C,A) ; AD = dif(D,A)
CD = dif(D,C) ; CA = dif(A,C) ; CB = dif(B,C)
_A = projection(CA,CD)
_B = projection(CB,CD)
_C = projection(AC,AB)
_D = projection(AD,AB)
return [_A,_B,_C,_D]
def Order(a,b):
crs = cross(a,b)
if crs > 0 : return "COUNTER_CLOCKWISE"
elif crs < 0 : return "CLOCKWISE"
else:
if dot(a,b) < 0 : return "ONLINE_BACK"
elif dot(a,a) < dot(b,b) : return "ONLINE_FRONT"
else : return "ON_SEGMENT"
q = int(input())
for i in range(q):
a,b,c,d,e,f,g,h = [int(i) for i in input().split()]
A = [a,b] ; B = [c,d] ; C = [e,f] ; D = [g,h]
l = Line(A,B) ; m = Line(C,D)
if isec(l,m):
print(0.0)
continue
_A,_B,_C,_D = proj(A,B,C,D)
AB = dif(B,A) ; CD = dif(D,C)
A_C = dif(_C,A) ; A_D = dif(_D,A) ; C_A = dif(_A,C) ; C_B = dif(_B,C)
DIST = [dist(A,C),dist(A,D),dist(B,C),dist(B,D),dist(_A,A),dist(_B,B),dist(_C,C),dist(_D,D)]
fun = lambda x : x != "ON_SEGMENT"
if fun(Order(CD,C_A)) : DIST[4] = sys.maxsize
if fun(Order(CD,C_B)) : DIST[5] = sys.maxsize
if fun(Order(AB,A_C)) : DIST[6] = sys.maxsize
if fun(Order(AB,A_D)) : DIST[7] = sys.maxsize
print(min(DIST)) | Traceback (most recent call last):
File "/tmp/tmpxzfik1pa/tmpyywdjsxk.py", line 40, in <module>
q = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s734971644 | p02297 | u279605379 | 1503643390 | Python | Python3 | py | Runtime Error | 0 | 0 | 222 | n = int(input())
P =[]
s = 0
for i in range(n):P.append([int(i) for i in input().split()])
P.append(P[0])
for i in range(n):
a = P[i][0] ; b = P[i][1]; c = P[i+1][0] ; P[i+1][1]
s += a * d - b * c
print(abs(s)*0.5) | Traceback (most recent call last):
File "/tmp/tmp560cnt27/tmp1skca_u7.py", line 1, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s906876742 | p02297 | u279605379 | 1503643720 | Python | Python3 | py | Runtime Error | 0 | 0 | 245 | n = int(input())
P =[]
s = 0
x0,y0 = [int(i) for i in input().split()]
for i in range(n):
x,y = [int(i) for i in input().split()]
P.append([x-x0,y-y0])
for i in range(n-2):
s += P[i][0]*P[i+1][1] - P[i][1]*P[i+1][0]
print(abs(s)*0.5) | Traceback (most recent call last):
File "/tmp/tmpv9s6e2j_/tmp48v47py6.py", line 1, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s096938662 | p02297 | u279605379 | 1503644545 | Python | Python3 | py | Runtime Error | 0 | 0 | 186 | n = int(input())
P =[]
s = 0
x,y =
for _ in range(n):P.append([int(i) for i in input().split()])
P.append(P[0])
for j in range(n):s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5) | File "/tmp/tmpjjqkkwpe/tmpupiwa8uc.py", line 4
x,y =
^
SyntaxError: invalid syntax
| |
s239468209 | p02297 | u279605379 | 1503646038 | Python | Python3 | py | Runtime Error | 0 | 0 | 183 | n = int(input())
P =[]
s = 0
for _ in range(n):P.append([int(-i) for i in input().split()])
P.append(P[0])
for j in range(n):s += P[j][1]*P[j+1][0] - P[j][0] * P[j+1][1]
print(s*0.5) | Traceback (most recent call last):
File "/tmp/tmpkzgto_am/tmp0gxf6lkx.py", line 1, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s608355396 | p02297 | u279605379 | 1503646346 | Python | Python3 | py | Runtime Error | 0 | 0 | 166 | n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P += [int(i) for i in input().split()]
P+=P[0]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5) | Traceback (most recent call last):
File "/tmp/tmpn3hu61oi/tmpmtjd8t5f.py", line 1, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s469875526 | p02297 | u279605379 | 1503646429 | Python | Python3 | py | Runtime Error | 0 | 0 | 168 | n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P += [[int(i) for i in input().split()]]
P+=P[0]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5) | Traceback (most recent call last):
File "/tmp/tmpj6ft9_33/tmpzmtliem1.py", line 1, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s063086391 | p02297 | u279605379 | 1503646481 | Python | Python3 | py | Runtime Error | 0 | 0 | 171 | n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P.append([int(i) for i in input().split()])
P+=P[0]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5) | Traceback (most recent call last):
File "/tmp/tmpn1fl3c8_/tmp13snj927.py", line 1, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s841716791 | p02297 | u279605379 | 1503646597 | Python | Python3 | py | Runtime Error | 0 | 0 | 168 | n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P += [[int(i) for i in input().split()]]
P+=P[0]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5) | Traceback (most recent call last):
File "/tmp/tmpgal92wzi/tmpq6edxmhs.py", line 1, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s199495014 | p02297 | u279605379 | 1503648021 | Python | Python3 | py | Runtime Error | 0 | 0 | 153 | x=range(int(input()))
P=[]
_=0
for _ in x:P+=[[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:s+=P[j][0]*P[j+1][1]-P[j][1]*P[j+1][0]
print(s*0.5) | Traceback (most recent call last):
File "/tmp/tmpwnmd4r9_/tmpq_5ybagx.py", line 1, in <module>
x=range(int(input()))
^^^^^^^
EOFError: EOF when reading a line
| |
s421786670 | p02297 | u279605379 | 1503649688 | Python | Python3 | py | Runtime Error | 0 | 0 | 186 | x=range(int(input()))
f=lambda a,b,c,d : a*d - b*c
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
_=0
P+=[P[0]]
for j in x:_+=f(P[j][0],P[j][1],,P[j+1][0]P[j+1][1])
print(_*0.5) | File "/tmp/tmpkqv9wfnw/tmp3ddkgwbu.py", line 7
for j in x:_+=f(P[j][0],P[j][1],,P[j+1][0]P[j+1][1])
^
SyntaxError: invalid syntax
| |
s369091115 | p02298 | u279605379 | 1503973949 | Python | Python3 | py | Runtime Error | 0 | 0 | 273 | def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dif(a,b):return [x-y for x,y in zip(a,b)]
x = range(int(input()))
t = 1
P,Q = [],[]
for _ in x:P+=[[int(i) for i in input().split()]]
for i in x:Q+=[dif(P[i],P[i-1])]
for i in x:if cross(Q[i-1],Q[i]) < 0: t *= False
print(t) | File "/tmp/tmp_547p8y_/tmphuirh39a.py", line 9
for i in x:if cross(Q[i-1],Q[i]) < 0: t *= False
^^
SyntaxError: invalid syntax
| |
s066412379 | p02300 | u022407960 | 1480734769 | Python | Python3 | py | Runtime Error | 0 | 0 | 2007 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
7
2 1
0 0
1 2
2 2
4 2
1 3
3 3
output:
5
0 0
2 1
4 2
3 3
1 3
"""
import sys
from operator import attrgetter
EPS = 1e-9
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def check_ccw(p0, p1, p2):
a, b = p1 - p0, p2 - p0
if cross(a, b) > EPS:
# print('COUNTER_CLOCKWISE')
flag = 1
elif cross(a, b) < -1 * EPS:
# print('CLOCKWISE')
flag = -1
elif dot(a, b) < -1 * EPS:
# print('ONLINE_BACK')
flag = 2
elif abs(a) < abs(b):
# print('ONLINE_FRONT')
flag = -2
else:
# print('ON_SEGMENT')
flag = 0
return flag
def convex_check_Andrew(_polygon):
upper, lower = list(), list()
_polygon.sort(key=attrgetter('real', 'imag'))
upper.extend((_polygon[0], _polygon[1]))
lower.extend((_polygon[-1], _polygon[-2]))
for i in range(2, points):
n1 = len(upper)
while n1 >= 2 and check_ccw(upper[n1 - 2], upper[n1 - 1], _polygon[i]) == 1:
n1 -= 1
upper.pop()
upper.append(_polygon[i])
for j in range(points - 3, -1, -1):
n2 = len(lower)
while n2 >= 2 and check_ccw(lower[n2 - 2], lower[n2 - 1], _polygon[j]) == 1:
n2 -= 1
lower.pop()
lower.append(_polygon[j])
lower.reverse()
lower_min = min(lower)
min_index = lower.index(lower_min)
lower_right = lower[min_index:]
lower_left = lower[:min_index]
for k in range(len(upper) - 2, 0, -1):
lower_right.append(upper[k])
return lower_right + lower_left
if __name__ == '__main__':
_input = sys.stdin.readlines()
points = int(_input[0])
p_info = map(lambda x: x.split(), _input[1:])
polygon = [int(x) + int(y) * 1j for x, y in p_info]
ans = convex_check_Andrew(polygon)
print(len(ans))
for ele in ans:
print(int(ele.real), int(ele.imag)) | Traceback (most recent call last):
File "/tmp/tmpftdv02ny/tmplnxylnkm.py", line 92, in <module>
points = int(_input[0])
~~~~~~^^^
IndexError: list index out of range
| |
s699744478 | p02300 | u279605379 | 1504489964 | Python | Python3 | py | Runtime Error | 0 | 0 | 1125 | from collections import deque
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
del phU[-2]
if len(phU) == 2 :
break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
ph = phU + phL[1:-1]
return ph
n = int(input())
P = deque([])
for i in range(n):
P.append([[int(x) for x in input().split()]])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
for q in Q:
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpkavuzh8f/tmpejejlwd7.py", line 37, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s204205963 | p02300 | u279605379 | 1504490065 | Python | Python3 | py | Runtime Error | 0 | 0 | 1125 | #CGL_4-A Convex Polygon - Convex Hull
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
del phU[-2]
if len(phU) == 2 :
break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
ph = phU + phL[1:-1]
return ph
n = int(input())
P = []
for i in range(n):
P.append([[int(x) for x in input().split()]])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
for q in Q:
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmp4w8c0_hq/tmp54nqqqa9.py", line 36, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s994966776 | p02300 | u279605379 | 1504490231 | Python | Python3 | py | Runtime Error | 0 | 0 | 1130 | from collections import deque
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
ph.remove(phU[-2])
if len(phU) == 2 :
break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
ph = phU + phL[1:-1]
return ph
n = int(input())
P = deque([])
for i in range(n):
P.append([int(x) for x in input().split()])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
for q in Q:
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpt6o894df/tmpcto1go9u.py", line 37, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s131088327 | p02300 | u279605379 | 1504490493 | Python | Python3 | py | Runtime Error | 0 | 0 | 1105 | from collections import deque
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
del phU[-2]
if len(phU) == 2 :
break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
ph = phU + phL[1:-1]
return ph
n = int(input())
P = deque([])
for i in range(n):
P.append([int(x) for x in input().split()])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
for q in Q:
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpa2tkl74j/tmpkjdeohn4.py", line 36, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s002084068 | p02300 | u279605379 | 1504490671 | Python | Python3 | py | Runtime Error | 0 | 0 | 1101 | import heapq
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
del phU[-2]
if len(phU) == 2 :
break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
ph = phU + phL[1:-1]
return ph
n = int(input())
P = []
for i in range(n):
heappush(P,[int(x) for x in input().split()])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
for q in Q:
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpilsll0m5/tmpx_gvzq38.py", line 37, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s286781274 | p02300 | u279605379 | 1504490895 | Python | Python3 | py | Runtime Error | 0 | 0 | 1137 | from collections import deque
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
P = sorted(P)
phU = deque([P[0],P[1]])
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
del phU[-2]
if len(phU) == 2 :
break
phL = deque([P[-1],P[-2]])
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
ph = phU + phL[1:-1]
return ph
n = int(input())
P = deque([])
for i in range(n):
P.append([int(x) for x in input().split()])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
for q in Q:
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpxzq1tq1r/tmpkimdsfu_.py", line 37, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s766811066 | p02300 | u279605379 | 1504490998 | Python | Python3 | py | Runtime Error | 0 | 0 | 1167 | from collections import deque
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
P = sorted(P)
phU = deque(P[0],P[1])
print(phU)
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
del phU[-2]
if len(phU) == 2 :
break
phL = deque(P[-1],P[-2])
for p in P[-3::-1]:
print(phL)
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
ph = phU + phL[1:-1]
return ph
n = int(input())
P = deque([])
for i in range(n):
P.append([int(x) for x in input().split()])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
for q in Q:
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpkjavqve3/tmpf958gfun.py", line 39, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s516087077 | p02300 | u279605379 | 1504491892 | Python | Python3 | py | Runtime Error | 0 | 0 | 1197 | from collections import deque
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
P = sorted(P)
phU = deque([])
phU.append(P[0])
phU.append(P[1])
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
del phU[-2]
if len(phU) == 2 :
break
phL = deque([])
phL.append(P[-1])
phL.append(P[-2])
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
phL.pop()
phL.popleft()
ph = phU + phL
return ph
n = int(input())
P = deque([])
for i in range(n):
P.append([int(x) for x in input().split()])
Q = ConvexHullScan(P)
print(len(Q))
Q.reverse()
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
Q.rotate(-idx)
for q in Q:
print(q[0],q[1]) | Traceback (most recent call last):
File "/tmp/tmpd_zkf8ey/tmpcof3ucoe.py", line 43, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s516750710 | p02300 | u279605379 | 1504491970 | Python | Python3 | py | Runtime Error | 0 | 0 | 1235 | #CGL_4-A Convex Polygon - Convex Hull
from collections import deque
def isCLKWISE(ph):
a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
crs = a[0]*b[1] - a[1]*b[0]
if crs < 0 :
return False
else :
return True
def ConvexHullScan(P):
P = sorted(P)
phU = deque([])
phU.append(P[0])
phU.append(P[1])
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) :
break
else :
del phU[-2]
if len(phU) == 2 :
break
phL = deque([])
phL.append(P[-1])
phL.append(P[-2])
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) :
break
else :
del phL[-2]
if len(phL) == 2 :
break
phL.pop()
phL.popleft()
ph = phU + phL
return ph
n = int(input())
P = deque([])
for i in range(n):
P.append([int(x) for x in input().split()])
Q = ConvexHullScan(P)
print(len(Q))
Q.reverse()
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
Q.rotate(-idx)
for q in Q:
print(q[0],q[1]) | Traceback (most recent call last):
File "/tmp/tmpdmuvqb3v/tmprgirm_9j.py", line 44, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s042271882 | p02300 | u279605379 | 1504493544 | Python | Python3 | py | Runtime Error | 0 | 0 | 956 | import sys
def isCLKWISE(ph):
if (ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0 : return False
else : return True
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) : break
else :
del phU[-2]
if len(phU) == 2 : break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) : break
else :
del phL[-2]
if len(phL) == 2 : break
ph = phU + phL[1:-1]
return ph
input = sys.stdin.readlines()
n = int(input[0])
P = map(lambda x: x.split(), _input[1:])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpxv7gmsbh/tmpk2bxbjl7.py", line 29, in <module>
n = int(input[0])
~~~~~^^^
IndexError: list index out of range
| |
s840246335 | p02300 | u279605379 | 1504493687 | Python | Python3 | py | Runtime Error | 0 | 0 | 958 | import sys
def isCLKWISE(ph):
if (ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0 : return False
else : return True
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) : break
else :
del phU[-2]
if len(phU) == 2 : break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) : break
else :
del phL[-2]
if len(phL) == 2 : break
ph = phU + phL[1:-1]
return ph
_input = sys.stdin.readlines()
n = int(_input[0])
P = map(lambda x: x.split(), _input[1:])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpijzw__9r/tmprzl0bocn.py", line 29, in <module>
n = int(_input[0])
~~~~~~^^^
IndexError: list index out of range
| |
s014657536 | p02300 | u279605379 | 1504498077 | Python | Python3 | py | Runtime Error | 0 | 0 | 913 | def isCLKWISE(ph):
return ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) >= 0
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) : break
else :
del phU[-2]
if len(phU) == 2 : break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) : break
else :
del phL[-2]
if len(phL) == 2 : break
ph = phU + phL[1:-1]
return ph
n = range(int(input()))
P = []
for i in n:
P.append([int(x) for x in input().split()])
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1]) | File "/tmp/tmpk6ihnycb/tmp8n91231g.py", line 2
return ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) >= 0
^
SyntaxError: unmatched ')'
| |
s114454075 | p02300 | u279605379 | 1504498377 | Python | Python3 | py | Runtime Error | 0 | 0 | 912 | def isCLKWISE(ph):
return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
def ConvexHullScan(P):
P.sort()
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) : break
else :
del phU[-2]
if len(phU) == 2 : break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) : break
else :
del phL[-2]
if len(phL) == 2 : break
ph = phU + phL[1:-1]
return ph
n = range(int(input()))
P = []
for i in n:
P.append([int(x) for x in input().split()])
Q = ConvexHullScan(P).reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmp5_6yt86y/tmpc2ft05k6.py", line 25, in <module>
n = range(int(input()))
^^^^^^^
EOFError: EOF when reading a line
| |
s078657193 | p02300 | u279605379 | 1504498733 | Python | Python3 | py | Runtime Error | 0 | 0 | 943 | from collections import deque
def isCLKWISE(ph):
return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) : break
else :
del phU[-2]
if len(phU) == 2 : break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) : break
else :
del phL[-2]
if len(phL) == 2 : break
ph = phU + phL[1:-1]
return ph
n = range(int(input()))
P = []
for i in n : P.append([int(x) for x in input().split()])
Q = deque(ConvexHullScan(P))
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q.rotate(idx)
for r in R : print(r[0],r[1]) | Traceback (most recent call last):
File "/tmp/tmpi3j_p42j/tmp1kbo_c8f.py", line 27, in <module>
n = range(int(input()))
^^^^^^^
EOFError: EOF when reading a line
| |
s043546654 | p02300 | u279605379 | 1504498778 | Python | Python3 | py | Runtime Error | 0 | 0 | 939 | from collections import deque
def isCLKWISE(ph):
return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
def ConvexHullScan(P):
P = sorted(P)
phU = [P[0],P[1]]
for p in P[2:]:
phU.append(p)
while(True):
if isCLKWISE(phU) : break
else :
del phU[-2]
if len(phU) == 2 : break
phL = [P[-1],P[-2]]
for p in P[-3::-1]:
phL.append(p)
while(True):
if isCLKWISE(phL) : break
else :
del phL[-2]
if len(phL) == 2 : break
ph = phU + phL[1:-1]
return ph
n = range(int(input()))
P = []
for i in n : P.append([int(x) for x in input().split()])
Q = deque(ConvexHullScan(P))
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
Q.rotate(idx)
for r in Q : print(q[0],q[1]) | Traceback (most recent call last):
File "/tmp/tmpw01bsy3e/tmpvfhw7rkx.py", line 27, in <module>
n = range(int(input()))
^^^^^^^
EOFError: EOF when reading a line
| |
s420149968 | p02300 | u279605379 | 1504501572 | Python | Python3 | py | Runtime Error | 0 | 0 | 891 | def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
def ConvexHullScan(P) :
P = sorted(P)
phU = []
phU.append(P[0])
phU.append(P[1])
for p in P[2:] :
phU.append(p)
if isCLKWISE(phU) : continue
while(True):
del phU[-2]
try:
if isCLKWISE(phU) : break
except IndexError : break
phL = []
phL.append(P[-1])
phL.append(P[-2])
for p in P[-3::-1] :
phL.append(p)
if isCLKWISE(phL) : continue
while(True) :
del phL[-2]
try:
if isCLKWISE(phL) : break
except IndexError : break
del phL[0]
del phL[-1]
ph = phU + phL
return ph
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
print(len(P.reverse()))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
for p in P[idx:] + P[:idx] : print(p[0],p[1]) | Traceback (most recent call last):
File "/tmp/tmpfrwn3ai6/tmpk33zm93p.py", line 32, in <module>
n = range(int(input()))
^^^^^^^
EOFError: EOF when reading a line
| |
s940070028 | p02300 | u279605379 | 1504501752 | Python | Python3 | py | Runtime Error | 0 | 0 | 899 | def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
def ConvexHullScan(P) :
P = sorted(P)
phU = []
phU.append(P[0])
phU.append(P[1])
for p in P[2:] :
phU.append(p)
if isCLKWISE(phU) : continue
while(True)???:
del phU[-2]
try???:
if isCLKWISE(phU) : break
except IndexError : break
phL = []
phL.append(P[-1])
phL.append(P[-2])
for p in P[-3::-1] :
phL.append(p)
if isCLKWISE(phL) : continue
while(True) :
del phL[-2]
try:
if isCLKWISE(phL) : break
except IndexError : break
del phL[0]
del phL[-1]
ph = phU + phL
return ph
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
for p in P[idx:] + P[:idx] : print(p[0],p[1]) | File "/tmp/tmpt1hfvr2e/tmpxh97r9q2.py", line 11
while(True)???:
^
SyntaxError: invalid syntax
| |
s966678289 | p02300 | u279605379 | 1504501778 | Python | Python3 | py | Runtime Error | 0 | 0 | 938 | #sort ??§??????????????????????????????
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
def ConvexHullScan(P) :
P = sorted(P)
phU = []
phU.append(P[0])
phU.append(P[1])
for p in P[2:] :
phU.append(p)
if isCLKWISE(phU) : continue
while(True) :
del phU[-2]
try???:
if isCLKWISE(phU) : break
except IndexError : break
phL = []
phL.append(P[-1])
phL.append(P[-2])
for p in P[-3::-1] :
phL.append(p)
if isCLKWISE(phL) : continue
while(True) :
del phL[-2]
try:
if isCLKWISE(phL) : break
except IndexError : break
del phL[0]
del phL[-1]
ph = phU + phL
return ph
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
for p in P[idx:] + P[:idx] : print(p[0],p[1]) | File "/tmp/tmpiik9f6f6/tmpkcpo39a5.py", line 14
try???:
^
SyntaxError: expected ':'
| |
s828181379 | p02300 | u559070407 | 1515975366 | Python | Python3 | py | Runtime Error | 0 | 0 | 1315 | # O(NlgN) time
# build lower hull and upper hull in clockwise, concatenate them get convex hull
def convexHull(points):
assert len(points) > 0
points = sorted(set(points))
# build lower hull
lower = []
for p in points:
# cross(o, a, b) <= 0 not clockwise
while len(lower) >= 2 and cross(lower[-2], lower[-1], p) <= 0:
lower.pop()
lower.append(p)
# build upper hull
upper = []
for p in points[::-1]:
while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 0:
upper.pop()
upper.append(p)
# concatenation of the lower and upper hulls gives the convex hull
return lower[:-1] + upper[:-1]
# cross product of OA and OB vectors
# U(ou) = u1x + u2y, V(ov) = v1x + v2y
# UxV = det |u1 u2| = (u1*v2) - (v1*u2) = (u[0]-o[0])*(v[1]-o[1]) - (u[1]-o[1])*(v[0]-o[0])
# |v1 v2|
def cross(O, A, B):
return (A[0] - O[0]) * (B[1] - O[1]) - (A[1] - O[1]) * (B[0] - O[0])
# assert convexHull([(i//10, i%10) for i in range(100)]) == [(0, 0), (9, 0), (9, 9), (0, 9)]
if __name__ == '__main__':
_input = sys.stdin.readlines()
points = int(_input[0])
p_info = map(lambda x: x.split(), _input[1:])
polygon = [(int(x), int(y)) for x, y in p_info]
ans = convexHull(polygon)
print(len(ans))
for x, y in ans:
print(x, y)
| Traceback (most recent call last):
File "/tmp/tmp6s66gxw8/tmpsimswinl.py", line 42, in <module>
_input = sys.stdin.readlines()
^^^
NameError: name 'sys' is not defined
| |
s268940821 | p02301 | u072053884 | 1492579255 | Python | Python3 | py | Runtime Error | 40 | 8188 | 1102 | # Cross product
def cross(p1, p2, q1, q2):
p = p2 - p1
q = q2 - q1
return p.real * q.imag - p.imag * q.real
# Rotating calipers
def convex_diameter(points, n):
points.append(points[0])
p0 = points[0]
p1 = points[1]
for i, (q1, q2) in enumerate(zip(points[1:], points[2:]), start=1):
if cross(p0, p1, q1, q2) <= 0:
break
max_d = abs(points[i] - points[0])
points.append(points[1])
side1 = zip(points[0:i+1], points[1:i+2])
side2 = zip(points[i:n+1], points[i+1:])
p1, p2 = side1.__next__()
q1, q2 = side2.__next__()
for i in range(n - 1):
if cross(p1, p2, q1, q2) > 0:
q1, q2 = side2.__next__()
else:
p1, p2 = side1.__next__()
max_d = max(max_d, abs(p1 - q1))
return max_d
# Acceptance of input
def string_to_complex(s):
x, y = map(float, s.split())
return x + y * 1j
import sys
file_input = sys.stdin
n = int(file_input.readline())
P = [string_to_complex(line) for line in file_input]
# Output
ans = convex_diameter(P, n)
print('{:f}'.format(ans)) | Traceback (most recent call last):
File "/tmp/tmpy90kt1_v/tmpjv3hzk_h.py", line 42, in <module>
n = int(file_input.readline())
^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s083174513 | p02301 | u072053884 | 1492580173 | Python | Python3 | py | Runtime Error | 60 | 8276 | 1101 | # Cross product
def cross(p1, p2, q1, q2):
p = p2 - p1
q = q2 - q1
return p.real * q.imag - p.imag * q.real
# Rotating calipers
def convex_diameter(points, n):
points.append(points[0])
p0 = points[0]
p1 = points[1]
for i, (q1, q2) in enumerate(zip(points[1:], points[2:]), start=1):
if cross(p0, p1, q1, q2) < 0:
break
max_d = abs(points[i] - points[0])
points.append(points[1])
side1 = zip(points[0:i+1], points[1:i+2])
side2 = zip(points[i:n+1], points[i+1:])
p1, p2 = side1.__next__()
q1, q2 = side2.__next__()
for i in range(n - 1):
if cross(p1, p2, q1, q2) > 0:
q1, q2 = side2.__next__()
else:
p1, p2 = side1.__next__()
max_d = max(max_d, abs(p1 - q1))
return max_d
# Acceptance of input
def string_to_complex(s):
x, y = map(float, s.split())
return x + y * 1j
import sys
file_input = sys.stdin
n = int(file_input.readline())
P = [string_to_complex(line) for line in file_input]
# Output
ans = convex_diameter(P, n)
print('{:f}'.format(ans)) | Traceback (most recent call last):
File "/tmp/tmpk9uvhm1f/tmpzc12ecel.py", line 42, in <module>
n = int(file_input.readline())
^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s114305041 | p02301 | u260980560 | 1499962573 | Python | Python3 | py | Runtime Error | 0 | 0 | 1578 | from math import sqrt
# ??????
def cross(P0, P1, P2):
x0, y0 = P0; x1, y1 = P1; x2, y2 = P2
x1 -= x0; x2 -= x0
y1 -= y0; y2 -= y0
return x1*y2 - x2*y1
# ??????
def dot(P0, P1, P2):
x0, y0 = P0; x1, y1 = P1; x2, y2 = P2
x1 -= x0; x2 -= x0
y1 -= y0; y2 -= y0
return x1*x2 + y1*y2
# 2??????????????¢?????????
def dist2(P0, P1):
x0, y0 = P0; x1, y1 = P1
return (x1 - x0)**2 + (y1 - y0)**2
# ??????
# ??\???????????????????????§?¨???????
def convex_hull(PS):
QS = []
n = len(PS)
for P in PS:
while len(QS)>1 and cross(QS[-1], QS[-2], P) > 0:
QS.pop()
QS.append(P)
k = len(QS)
RS = reversed(PS); next(RS)
for P in RS:
while len(QS)>k and cross(QS[-1], QS[-2], P) > 0:
QS.pop()
QS.append(P)
return QS
# ?????£???????????? (?????????????¨????)
def cross4(S0, S1, T0, T1):
x0, y0 = S0; x1, y1 = S1
X0, Y0 = T0; X1, Y1 = T1
return (x1-x0)*(Y1-Y0) - (y1-y0)*(X1-X0)
def calipers(PS):
QS = convex_hull(PS)
n = len(QS)
if n == 2:
return sqrt(dist2(*QS))
i = j = 0
for k in range(n):
if QS[k] < QS[i]: i = k
if QS[j] < QS[k]: j = k
res = 0
si = i; sj = j
while i != sj or j != si:
res = max(res, dist2(QS[i], QS[j]))
if cross4(QS[i], QS[i-n+1], QS[j], QS[j-n+1]) < 0:
i = (i + 1) % n
else:
j = (j + 1) % n
return sqrt(res)
n = int(input())
PS = [[*map(float, input().split())] for i in range(n)]
PS.sort()
print("%.09f" % calipers(PS)) | Traceback (most recent call last):
File "/tmp/tmp735t3vod/tmpbhm3l3fg.py", line 65, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s054255167 | p02301 | u260980560 | 1499962788 | Python | Python3 | py | Runtime Error | 0 | 0 | 1469 | from math import sqrt
def cross(P0, P1, P2):
x0, y0 = P0; x1, y1 = P1; x2, y2 = P2
x1 -= x0; x2 -= x0
y1 -= y0; y2 -= y0
return x1*y2 - x2*y1
def dot(P0, P1, P2):
x0, y0 = P0; x1, y1 = P1; x2, y2 = P2
x1 -= x0; x2 -= x0
y1 -= y0; y2 -= y0
return x1*x2 + y1*y2
def dist2(P0, P1):
x0, y0 = P0; x1, y1 = P1
return (x1 - x0)**2 + (y1 - y0)**2
def convex_hull(PS):
QS = []
n = len(PS)
if n==1:
return PS[:]
for P in PS:
while len(QS)>1 and cross(QS[-1], QS[-2], P) > 0:
QS.pop()
QS.append(P)
k = len(QS)
RS = reversed(PS); next(RS)
for P in RS:
while len(QS)>k and cross(QS[-1], QS[-2], P) > 0:
QS.pop()
QS.append(P)
return QS
def cross4(S0, S1, T0, T1):
x0, y0 = S0; x1, y1 = S1
X0, Y0 = T0; X1, Y1 = T1
return (x1-x0)*(Y1-Y0) - (y1-y0)*(X1-X0)
def calipers(PS):
QS = convex_hull(PS)
n = len(QS)
if n == 2:
return sqrt(dist2(*QS))
i = j = 0
for k in range(n):
if QS[k] < QS[i]: i = k
if QS[j] < QS[k]: j = k
res = 0
si = i; sj = j
while i != sj or j != si:
res = max(res, dist2(QS[i], QS[j]))
if cross4(QS[i], QS[i-n+1], QS[j], QS[j-n+1]) < 0:
i = (i + 1) % n
else:
j = (j + 1) % n
return sqrt(res)
n = int(input())
PS = [[*map(float, input().split())] for i in range(n)]
PS.sort()
print("%.09f" % calipers(PS)) | Traceback (most recent call last):
File "/tmp/tmptngc282d/tmpwm78y5cv.py", line 59, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s814248362 | p02302 | u567380442 | 1428742800 | Python | Python3 | py | Runtime Error | 0 | 0 | 1727 | from sys import stdin
readline = stdin.readline
from enum import Enum
direction = Enum('direction', 'CCW CW CAB ABC ACB')
class vector:
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def ccw(a, b, c):
b -= a
c -= a
if vector.cross(b, c) > 0:
return direction.CCW
if vector.cross(b, c) < 0:
return direction.CW
if vector.dot(b, c) < 0:
return direction.CAB
if vector.abs(b) < abs(c):
return direction.ABC
return direction.ACB
def polygon(p):
return 0.5 * sum(vector.cross(p[i - 1], p[i]) for i in range(len(p)))
def intersection(p1, p2, p3, p4):
a1 = p4 - p2
b1 = p2 - p3
b2 = p1 - p2
s1 = vector.cross(a1, b2) / 2
s2 = vector.cross(a1, b1) / 2
c1 = p1 + (p3 - p1) * s1 / (s1 + s2)
return c1
def main():
n = int(readline())
p = [map(int, readline().split()) for _ in range(n)]
p = [x + y * 1j for x, y in p]
q = int(readline())
for _ in range(q):
p1x, p1y, p2x, p2y = map(int, readline().split())
p1, p2 = p1x + p1y * 1j, p2x + p2y * 1j
pre_tmp = vector.ccw(p[-1], p1, p2)
left = []
for i in range(len(p)):
tmp = vector.ccw(p[i], p1, p2)
if pre_tmp != tmp and all(i in (direction.CW, direction.CCW) for i in (pre_tmp, tmp)):
c1 = vector.intersection(p1, p[i - 1], p2, p[i])
left.append(c1)
if tmp != direction.CW:
left.append(p[i])
pre_tmp = tmp
print(vector.polygon(left))
main() | Traceback (most recent call last):
File "/tmp/tmpcbgae94t/tmpps6va8th.py", line 64, in <module>
main()
File "/tmp/tmpcbgae94t/tmpps6va8th.py", line 43, in main
n = int(readline())
^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s673194337 | p02302 | u567380442 | 1428743094 | Python | Python3 | py | Runtime Error | 0 | 0 | 1748 | from sys import stdin
readline = stdin.readline
from enum import Enum
direction = Enum('direction', 'CCW CW CAB ABC ACB')
class vector:
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def ccw(a, b, c):
b -= a
c -= a
if vector.cross(b, c) > 0:
return direction.CCW
if vector.cross(b, c) < 0:
return direction.CW
if vector.dot(b, c) < 0:
return direction.CAB
if vector.abs(b) < abs(c):
return direction.ABC
return direction.ACB
def polygon(p):
return 0.5 * sum(vector.cross(p[i - 1], p[i]) for i in range(len(p)))
def intersection(p1, p2, p3, p4):
a1 = p4 - p2
b1 = p2 - p3
b2 = p1 - p2
s1 = vector.cross(a1, b2) / 2
s2 = vector.cross(a1, b1) / 2
c1 = p1 + (p3 - p1) * s1 / (s1 + s2)
return c1
def main():
n = int(readline())
p = [map(float, readline().split()) for _ in range(n)]
p = [x + y * 1j for x, y in p]
q = int(readline())
for _ in range(q):
p1x, p1y, p2x, p2y = map(float, readline().split())
p1, p2 = p1x + p1y * 1j, p2x + p2y * 1j
pre_tmp = vector.ccw(p[-1], p1, p2)
left = []
for i in range(len(p)):
tmp = vector.ccw(p[i], p1, p2)
if pre_tmp != tmp and all(i in (direction.CW, direction.CCW) for i in (pre_tmp, tmp)):
c1 = vector.intersection(p1, p[i - 1], p2, p[i])
left.append(c1)
if tmp != direction.CW:
left.append(p[i])
pre_tmp = tmp
print('{:.6f}'.format(vector.polygon(left)))
main() | Traceback (most recent call last):
File "/tmp/tmpzk8c3gid/tmp52880awd.py", line 64, in <module>
main()
File "/tmp/tmpzk8c3gid/tmp52880awd.py", line 43, in main
n = int(readline())
^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s912846154 | p02302 | u567380442 | 1428749083 | Python | Python3 | py | Runtime Error | 0 | 0 | 1792 | from sys import stdin
readline = stdin.readline
from enum import Enum
direction = Enum('direction', 'CCW CW CAB ABC ACB')
class vector:
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def ccw(a, b, c):
b -= a
c -= a
if vector.cross(b, c) > 0:
return direction.CCW
if vector.cross(b, c) < 0:
return direction.CW
if vector.dot(b, c) < 0:
return direction.CAB
if vector.abs(b) < abs(c):
return direction.ABC
return direction.ACB
def polygon(p):
if len(p) < 3:
return 0
return 0.5 * sum(vector.cross(p[i - 1], p[i]) for i in range(len(p)))
def intersection(p1, p2, p3, p4):
a1 = p4 - p2
b1 = p2 - p3
b2 = p1 - p2
s1 = vector.cross(a1, b2) / 2
s2 = vector.cross(a1, b1) / 2
c1 = p1 + (p3 - p1) * s1 / (s1 + s2)
return c1
def main():
n = int(readline())
p = [map(float, readline().split()) for _ in range(n)]
p = [x + y * 1j for x, y in p]
q = int(readline())
for _ in range(q):
p1x, p1y, p2x, p2y = map(float, readline().split())
p1, p2 = p1x + p1y * 1j, p2x + p2y * 1j
pre_tmp = vector.ccw(p[-1], p1, p2)
left = []
for i in range(len(p)):
tmp = vector.ccw(p[i], p1, p2)
if pre_tmp != tmp and all(i in (direction.CW, direction.CCW) for i in (pre_tmp, tmp)):
c1 = vector.intersection(p1, p[i - 1], p2, p[i])
left.append(c1)
if tmp != direction.CW:
left.append(p[i])
pre_tmp = tmp
print('{:.6f}'.format(vector.polygon(left)))
main() | Traceback (most recent call last):
File "/tmp/tmpzkq_2gqe/tmpnip3m6ce.py", line 66, in <module>
main()
File "/tmp/tmpzkq_2gqe/tmpnip3m6ce.py", line 45, in main
n = int(readline())
^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s520636952 | p02302 | u567380442 | 1428749547 | Python | Python3 | py | Runtime Error | 0 | 0 | 1785 | from sys import stdin
readline = stdin.readline
from enum import Enum
direction = Enum('direction', 'CCW CW CAB ABC ACB')
class vector:
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def ccw(a, b, c):
b -= a
c -= a
if vector.cross(b, c) > 0:
return direction.CCW
if vector.cross(b, c) < 0:
return direction.CW
if vector.dot(b, c) < 0:
return direction.CAB
if abs(b) < abs(c):
return direction.ABC
return direction.ACB
def polygon(p):
if len(p) < 3:
return 0
return 0.5 * sum(vector.cross(p[i - 1], p[i]) for i in range(len(p)))
def intersection(p1, p2, p3, p4):
a1 = p4 - p2
b1 = p2 - p3
b2 = p1 - p2
s1 = vector.cross(a1, b2) / 2
s2 = vector.cross(a1, b1) / 2
c1 = p1 + (p3 - p1) * s1 / (s1 + s2)
return c1
def main():
n = int(readline())
p = [map(float, readline().split()) for _ in range(n)]
p = [x + y * 1j for x, y in p]
q = int(readline())
for _ in range(q):
p1x, p1y, p2x, p2y = map(float, readline().split())
p1, p2 = p1x + p1y * 1j, p2x + p2y * 1j
pre_tmp = vector.ccw(p[-1], p1, p2)
left = []
for i in range(len(p)):
tmp = vector.ccw(p[i], p1, p2)
if pre_tmp != tmp and all(i in (direction.CW, direction.CCW) for i in (pre_tmp, tmp)):
c1 = vector.intersection(p1, p[i - 1], p2, p[i])
left.append(c1)
if tmp != direction.CW:
left.append(p[i])
pre_tmp = tmp
print('{:.6f}'.format(vector.polygon(left)))
main() | Traceback (most recent call last):
File "/tmp/tmpf7003sd6/tmp3jsues7i.py", line 66, in <module>
main()
File "/tmp/tmpf7003sd6/tmp3jsues7i.py", line 45, in main
n = int(readline())
^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s851294381 | p02302 | u567380442 | 1428749931 | Python | Python3 | py | Runtime Error | 0 | 0 | 1831 | from sys import stdin
readline = stdin.readline
from enum import Enum
direction = Enum('direction', 'CCW CW CAB ABC ACB')
class vector:
def cross(a, b):
return a.real * b.imag - a.imag * b.real
def dot(a, b):
return a.real * b.real + a.imag * b.imag
def ccw(a, b, c):
b -= a
c -= a
if vector.cross(b, c) > 0:
return direction.CCW
if vector.cross(b, c) < 0:
return direction.CW
if vector.dot(b, c) < 0:
return direction.CAB
if abs(b) < abs(c):
return direction.ABC
return direction.ACB
def polygon(p):
if len(p) < 3:
return 0
return 0.5 * sum(vector.cross(p[i - 1], p[i]) for i in range(len(p)))
def intersection(p1, p2, p3, p4):
a1 = p4 - p2
b1 = p2 - p3
b2 = p1 - p2
s1 = vector.cross(a1, b2) / 2
s2 = vector.cross(a1, b1) / 2
if s1 + s2 == 0:
return 0
c1 = p1 + (p3 - p1) * s1 / (s1 + s2)
return c1
def main():
n = int(readline())
p = [map(float, readline().split()) for _ in range(n)]
p = [x + y * 1j for x, y in p]
q = int(readline())
for _ in range(q):
p1x, p1y, p2x, p2y = map(float, readline().split())
p1, p2 = p1x + p1y * 1j, p2x + p2y * 1j
pre_tmp = vector.ccw(p[-1], p1, p2)
left = []
for i in range(len(p)):
tmp = vector.ccw(p[i], p1, p2)
if pre_tmp != tmp and all(i in (direction.CW, direction.CCW) for i in (pre_tmp, tmp)):
c1 = vector.intersection(p1, p[i - 1], p2, p[i])
left.append(c1)
if tmp != direction.CW:
left.append(p[i])
pre_tmp = tmp
print('{:.6f}'.format(vector.polygon(left)))
main() | Traceback (most recent call last):
File "/tmp/tmp9bddokmp/tmpogokf7hi.py", line 68, in <module>
main()
File "/tmp/tmp9bddokmp/tmpogokf7hi.py", line 47, in main
n = int(readline())
^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s081566786 | p02302 | u260980560 | 1467437882 | Python | Python | py | Runtime Error | 10 | 6484 | 1041 | n = input()
ps = [map(int, raw_input().split()) for i in xrange(n)]
def intersection(p1, p2, q1, q2):
dx0 = p2[0] - p1[0]
dy0 = p2[1] - p1[1]
dx1 = q2[0] - q1[0]
dy1 = q2[1] - q1[1]
a = dy0*dx1; b = dy1*dx0; c = dx0*dx1; d = dy0*dy1
if a == b: return None
x = (a*p1[0] - b*q1[0] + c*(q1[1] - p1[1])) / float(a - b)
y = (c*p1[1] - a*q1[1] + d*(q1[0] - p1[0])) / float(b - a)
return x, y
def cross(a, b, c):
return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])
def calc_area(ps):
return abs(sum(ps[i][0]*ps[i-1][1] - ps[i][1]*ps[i-1][0] for i in xrange(n))) / 2.
for t in xrange(input()):
vs = []
x1, y1, x2, y2 = map(int, raw_input().split())
p1 = (x1, y1); p2 = (x2, y2)
for i in xrange(n):
q1 = ps[i-1]; q2 = ps[i]
if cross(p1, p2, q1) * cross(p1, p2, q2) <= 0:
r = intersection(p1, p2, q1, q2)
if r is not None:
vs.append(r)
if cross(p1, p2, q2) >= 0:
vs.append(q2)
print "%.09f" % calc_area(vs) | File "/tmp/tmpzy2sdh2e/tmpd_v30aa8.py", line 29
print "%.09f" % calc_area(vs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
| |
s907422917 | p02302 | u797673668 | 1473068673 | Python | Python3 | py | Runtime Error | 20 | 7832 | 1017 | def cross(a, b):
return a.real * b.imag - a.imag * b.real
def cross_point(c, d):
l = d - c
v1 = cross(lv, l)
v2 = cross(lv, lt - c)
return c + v2 / v1 * l
n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
point0 = points.pop(0)
points.append(point0)
q = int(input())
while q:
x1, y1, x2, y2 = map(int, input().split())
ls, lt = (x1 + 1j * y1, x2 + 1j * y2)
lv = lt - ls
area = 0
prev = point0
prev_flag = cross(lv, prev - ls) >= 0
cp1, cp2 = None, None
for p in points:
curr_flag = cross(lv, p - ls) >= 0
if prev_flag and curr_flag:
area += cross(prev, p)
elif prev_flag != curr_flag:
cp = cross_point(prev, p)
if prev_flag:
area += cross(prev, cp)
cp1 = cp
else:
area += cross(cp, p)
cp2 = cp
prev, prev_flag = p, curr_flag
area += cross(cp1, cp2)
print(area / 2)
q -= 1 | Traceback (most recent call last):
File "/tmp/tmpgq0d5_bo/tmpnqginh4l.py", line 12, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s440759152 | p02302 | u072053884 | 1493205490 | Python | Python3 | py | Runtime Error | 30 | 7776 | 1963 | # cross point
def cross(c1, c2):
return c1.real * c2.imag - c1.imag * c2.real
def cross_point(p1, p2, p3, p4):
# p1 and p2 are points on a segment.
# p3 and p4 are points on the other segment.
base = p4 - p3
hypo1 = p1 - p3
hypo2 = p2 - p3
d1 = cross(base, hypo1) / abs(base)
d2 = cross(base, hypo2) / abs(base)
cp = p1 + d1 / (d1 - d2) * (p2 - p1)
return cp
# area of a triangle
def _area_of_triangle(c1, c2, c3):
v1 = c2 - c1
v2 = c3 - c1
return abs(v1.real * v2.imag - v1.imag * v2.real) / 2
# convex cut
def convex_cut(points, c1, c2):
points.append(points[0])
ref_vec = c2 - c1
for i, segment in enumerate(zip(points, points[1:])):
p1, p2 = segment
cross1 = cross(ref_vec, p1 - c1)
cross2 = cross(ref_vec, p2 - c1)
if cross1 <= 0 and cross2 > 0:
cross_point1 = cross_point(c1, c2, p1, p2)
points = points[i+1:]
break
elif cross1 > 0 and cross2 <= 0:
cross_point1 = cross_point(c1, c2, p1, p2)
points = points[i::-1] + points[:i:-1]
break
cut_area = 0
for p1, p2 in zip(points, points[1:]):
if cross(ref_vec, p1 - c1) * cross(ref_vec, p2 - c1) <= 0:
cross_point2 = cross_point(c1, c2, p1, p2)
cut_area += _area_of_triangle(cross_point1, cross_point2, p1)
break
else:
cut_area += _area_of_triangle(cross_point1, p1, p2)
return cut_area
# acceptance of input
import sys
file_input = sys.stdin
n = int(file_input.readline())
def string_to_complex(s):
x, y = map(float, s.split())
return x + y * 1j
G = [string_to_complex(file_input.readline()) for i in range(n)]
# output
q = int(file_input.readline())
for line in file_input:
p1x, p1y, p2x, p2y = map(int, line.split())
p1 = p1x + p1y * 1j
p2 = p2x + p2y * 1j
ans = convex_cut(G.copy(), p1, p2)
print("{:f}".format(ans)) | Traceback (most recent call last):
File "/tmp/tmpoh9903ra/tmp_47eahxb.py", line 53, in <module>
n = int(file_input.readline())
^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s393985228 | p02303 | u567380442 | 1428802533 | Python | Python3 | py | Runtime Error | 0 | 0 | 818 | from sys import stdin
readline = stdin.readline
import operator
def norm(self):
return abs(self)
def closest_pair(p):
m = 0
p.sort(key=operator.attrgetter('real'))
d = float('inf')
for i in range(1, len(p)):
for j in reversed(range(m, i)):
tmp = abs(p[j] - p[i])
if d < tmp.real:
m += 1
break
elif d > tmp:
d = tmp
return d
from itertools import combinations
def brute_force(p):
return min(abs(p[i] - p[j]) for i, j in combinations(range(len(p)), 2))
@profile
def main():
n = int(readline())
p = [map(float, readline().split()) for _ in range(n)]
p = [x + y * 1j for x, y in p]
#print('{:.6f}'.format(brute_force(p)))
print('{:.6f}'.format(closest_pair(p)))
main() | Traceback (most recent call last):
File "/tmp/tmpydaao27i/tmpheykmqsc.py", line 30, in <module>
@profile
^^^^^^^
NameError: name 'profile' is not defined
| |
s877197473 | p02303 | u567380442 | 1428803134 | Python | Python3 | py | Runtime Error | 0 | 0 | 839 | from sys import stdin
import operator
readline = stdin.readline
def norm(self):
return abs(self)
def closest_pair(p):
m = 0
p.sort(key=operator.attrgetter('real'))
d = float('inf')
for i in range(1, len(p)):
for j in reversed(range(m, i)):
tmp = p[i] - p[j]
if d < tmp.real:
m = j + 1
break
tmp = abs(tmp)
if d > tmp:
d = tmp
return d
from itertools import combinations
def brute_force(p):
return min(abs(p[i] - p[j]) for i, j in combinations(range(len(p)), 2))
@profile
def main():
n = int(readline())
p = [map(float, readline().split()) for _ in range(n)]
p = [x + y * 1j for x, y in p]
# print('{:.6f}'.format(brute_force(p)))
print('{:.6f}'.format(closest_pair(p)))
main() | Traceback (most recent call last):
File "/tmp/tmpjvjtfyyd/tmpv4p0b60d.py", line 33, in <module>
@profile
^^^^^^^
NameError: name 'profile' is not defined
| |
s095914161 | p02303 | u657035709 | 1435966997 | Python | Python | py | Runtime Error | 20 | 4604 | 3665 | # #### CLOSEST PAIR O(N LOG N) ALGORITHM #### #
# points should be unique, otherwise the closest pair would be the repeated points
# also this will only find 1 pair with the smallest distance, in case there are multiple pairs with this same minimum distance
#import time
#start = time.time()
def halve(coord): # split into two halves by x-coordinate
L = len(coord) # luckily pts are already sorted
return [coord[:L/2], coord[L/2:]]
def dist(x, y): # for two points x(x0,x1) and y(y0,y1), what is the squared distance?
return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2
def splitpair(px, py, d): # only need to return a correct value if closest pair is split
xBar = px[(len(px)+1)/2][0]
Sy = [] # Sy will be the set of points (sorted by Y-coordinate) where the x-coord xi satisfies xBar-d <= xi <= xBar -d
for i in xrange(len(py)):
if xBar-d**0.5 <= py[i][0] <= xBar+d**0.5: # only consider a 'strip' around xBar that is 2*sqrt(d) wide
Sy.append(py[i])
bestpair = None # the coords of the best pair of points so far
bestD = d # the squared distance of the best pair of points
# now iterate through Sy for points that aren't more than 7 apart
for i in xrange(len(Sy)-2):
for j in xrange(1, min(8, len(Sy)-i-1)): # 7 next points
p, q = Sy[i], Sy[i+j]
if dist(p, q) < bestD:
bestpair = [p, q]
bestD = dist(p, q)
return bestpair
def convert(p1, p2): # convert 2 points into two pairs of pairs, first sorted by x, other sorted by y1
return [sorted([p1, p2]), sorted([p1, p2], key=lambda x: x[1])]
def solve(Px, Py): # where Px and Py are the points sorted by x and y coordinate respectively
# this function returns two closest points
assert len(Px) == len(Py) # make sure you have the same number of x and y coords
if len(Px) == 2:
return (Px, Py)
elif len(Px) == 3: # 3 points, brute force
p1, p2, p3 = [x for x in Px]
d12, d13, d23 = dist(p1, p2), dist(p1, p3), dist(p2, p3)
if min(d12, d13, d23) == d12:
return convert(p1, p2)
elif min(d12, d13, d23) == d13:
return convert(p1, p3)
else:
return convert(p2, p3)
else:
Qx, Rx = [x for x in halve(Px)]
Qy, Ry = [], []
k = Qx[-1][0]
for pt in Py:
if pt[0] <= k:
Qy.append(pt)
else:
Ry.append(pt)
assert len(Qx) == len(Qy)
assert len(Rx) == len(Ry)
# now use recursion. note ci is of the form [[x1,x2], [y1,y2]]
c1 = solve(Qx, Qy) # find the closest pair in left half
c2 = solve(Rx, Ry) # find the closest pair in the right half
D = min(dist(c1[0][0], c1[0][1]), dist(c2[0][0], c2[0][1]))
if D == dist(c1[0][0], c1[0][1]):
bestpair = c1
elif D == dist(c2[0][0], c2[0][1]):
bestpair = c2
c3 = splitpair(Px, Py, D) # find the closest split pair. this needs to be O(n) to get O(n log n) for entire algo
if c3 is not None:
return convert(c3[0], c3[1])
else:
return bestpair # else it's one of the c1 or c2
def main():
N = int(raw_input().split()[0]) # N is number of points
assert N >= 2
pts = [] # pairs of points, i.e pts = [[x1,y1], [x2,y2], ... , [xn,yn]]
# get all pairs of points into our list
for i in xrange(N):
pts.append([float(x) for x in raw_input().split()])
Px = sorted(pts) # sort the pts by x coordinate
Py = sorted(pts, key=lambda x: x[1]) # sort the pts by y coordinate
res = solve(Px, Py)
'''
# find the index of the points in pts
for i in xrange(len(pts)):
if pts[i] == res[0][0]:
ind1 = i
elif pts[i] == res[0][1]:
ind2 = i
d = dist(pts[ind1], pts[ind2]) ** 0.5
'''
print dist(res[0][0], res[0][1]) ** 0.5
if __name__ == '__main__':
main()
#print "%.2f %s" % (((time.time() - start) * 1000), "ms") | File "/tmp/tmp8u55yb1l/tmpcvbt2w0n.py", line 110
print dist(res[0][0], res[0][1]) ** 0.5
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
| |
s705593661 | p02303 | u657035709 | 1435967283 | Python | Python | py | Runtime Error | 30 | 4604 | 3743 | # #### CLOSEST PAIR O(N LOG N) ALGORITHM #### #
# points should be unique, otherwise the closest pair would be the repeated points
# also this will only find 1 pair with the smallest distance, in case there are multiple pairs with this same minimum distance
#import time
#start = time.time()
def halve(coord): # split into two halves by x-coordinate
L = len(coord) # luckily pts are already sorted
return [coord[:L/2], coord[L/2:]]
def dist(x, y): # for two points x(x0,x1) and y(y0,y1), what is the squared distance?
return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2
def splitpair(px, py, d): # only need to return a correct value if closest pair is split
xBar = px[(len(px)+1)/2][0]
Sy = [] # Sy will be the set of points (sorted by Y-coordinate) where the x-coord xi satisfies xBar-d <= xi <= xBar -d
for i in xrange(len(py)):
if xBar-d**0.5 <= py[i][0] <= xBar+d**0.5: # only consider a 'strip' around xBar that is 2*sqrt(d) wide
Sy.append(py[i])
bestpair = None # the coords of the best pair of points so far
bestD = d # the squared distance of the best pair of points
# now iterate through Sy for points that aren't more than 7 apart
for i in xrange(len(Sy)-2):
for j in xrange(1, min(8, len(Sy)-i-1)): # 7 next points
p, q = Sy[i], Sy[i+j]
if dist(p, q) < bestD:
bestpair = [p, q]
bestD = dist(p, q)
return bestpair
def convert(p1, p2): # convert 2 points into two pairs of pairs, first sorted by x, other sorted by y1
return [sorted([p1, p2]), sorted([p1, p2], key=lambda x: x[1])]
def solve(Px, Py): # where Px and Py are the points sorted by x and y coordinate respectively
# this function returns two closest points
assert len(Px) == len(Py) # make sure you have the same number of x and y coords
if len(Px) == 2:
return (Px, Py)
elif len(Px) == 3: # 3 points, brute force
p1, p2, p3 = [x for x in Px]
d12, d13, d23 = dist(p1, p2), dist(p1, p3), dist(p2, p3)
if min(d12, d13, d23) == d12:
return convert(p1, p2)
elif min(d12, d13, d23) == d13:
return convert(p1, p3)
else:
return convert(p2, p3)
else:
Qx, Rx = [x for x in halve(Px)]
Qy, Ry = [], []
k = Qx[-1][0]
for pt in Py: # this is linear time, you loop through Py exactly once
if pt[0] <= k and len(Qy) < len(Qx):
Qy.append(pt)
else:
Ry.append(pt)
assert len(Qx) == len(Qy)
assert len(Rx) == len(Ry)
# now use recursion. note ci is of the form [[x1,x2], [y1,y2]]
c1 = solve(Qx, Qy) # find the closest pair in left half
c2 = solve(Rx, Ry) # find the closest pair in the right half
D = min(dist(c1[0][0], c1[0][1]), dist(c2[0][0], c2[0][1]))
if D == dist(c1[0][0], c1[0][1]):
bestpair = c1
elif D == dist(c2[0][0], c2[0][1]):
bestpair = c2
c3 = splitpair(Px, Py, D) # find the closest split pair. this needs to be O(n) to get O(n log n) for entire algo
if c3 is not None:
return convert(c3[0], c3[1])
else:
return bestpair # else it's one of the c1 or c2
def main():
N = int(raw_input().split()[0]) # N is number of points
assert N >= 2
pts = [] # pairs of points, i.e pts = [[x1,y1], [x2,y2], ... , [xn,yn]]
# get all pairs of points into our list
for i in xrange(N):
pts.append([float(x) for x in raw_input().split()])
Px = sorted(pts) # sort the pts by x coordinate
Py = sorted(pts, key=lambda x: x[1]) # sort the pts by y coordinate
res = solve(Px, Py)
'''
# find the index of the points in pts
for i in xrange(len(pts)):
if pts[i] == res[0][0]:
ind1 = i
elif pts[i] == res[0][1]:
ind2 = i
d = dist(pts[ind1], pts[ind2]) ** 0.5
'''
print dist(res[0][0], res[0][1]) ** 0.5
if __name__ == '__main__':
main()
#print "%.2f %s" % (((time.time() - start) * 1000), "ms") | File "/tmp/tmpikfy_dds/tmpj9jm005i.py", line 110
print dist(res[0][0], res[0][1]) ** 0.5
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
| |
s953797478 | p02303 | u072053884 | 1492011599 | Python | Python3 | py | Runtime Error | 30 | 7664 | 2201 | import itertools
def _get_min_distance(points):
min_d = 400
for p1, p2 in itertools.combinations(points, 2):
min_d = min(min_d, abs(p1 - p2))
return min_d
# Search based on x axis
def closest_pair_distance_x(points):
n = len(points)
if n <= 3:
return _get_min_distance(points)
else:
mid = n // 2
left_points = points[:mid]
right_points = points[mid:]
d_Lmin = closest_pair_distance(left_points)
d_Rmin = closest_pair_distance(right_points)
dist = min(d_Lmin, d_Rmin)
min_d = dist
for lp in left_points[::-1]:
if right_points[0].real - lp.real >= dist:
break
for rp in right_points:
if rp.real -lp.real >= dist:
break
if lp.imag - dist < rp.imag < lp.imag + dist:
min_d = min(min_d, abs(lp - rp))
return min_d
# Search based on y axis
def closest_pair_distance_y(points):
n = len(points)
if n <= 3:
return _get_min_distance(points)
else:
mid = n // 2
lower_points = points[:mid]
upper_points = points[mid:]
d_Lmin = closest_pair_distance(lower_points)
d_Umin = closest_pair_distance(upper_points)
dist = min(d_Lmin, d_Umin)
min_d = dist
for lp in lower_points[::-1]:
if upper_points[0].imag - lp.imag >= dist:
break
for up in upper_points:
if up.imag -lp.imag >= dist:
break
if lp.real - dist < up.real < lp.real + dist:
min_d = min(min_d, abs(lp - up))
return min_d
# Acceptance of input
def string_to_complex(s):
x, y = map(float, s.split())
return x + y * 1j
import sys
file_input = sys.stdin
n = int(file_input.readline())
P = [string_to_complex(line) for line in file_input]
# Solve
P.sort(key = lambda c: (c.real, c.imag))
if P[-1].real - P[0].real >= P[-1].imag - P[0].imag:
ans = closest_pair_distance_x(P)
print('{:f}'.format(ans))
else:
P.sort(key = lambda c: c.imag)
ans = closest_pair_distance_y(P)
print('{:f}'.format(ans)) | Traceback (most recent call last):
File "/tmp/tmpuv4b0cmq/tmp8eef86r6.py", line 64, in <module>
n = int(file_input.readline())
^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
| |
s128007785 | p02303 | u797673668 | 1492589378 | Python | Python3 | py | Runtime Error | 20 | 7816 | 882 | from operator import attrgetter
from itertools import combinations
keys = [attrgetter('real'), attrgetter('imag')]
def solve(points, axis):
l = len(points)
if l < 20:
return min(abs(p2 - p1) for p1, p2 in combinations(points, 2))
m = n // 2
pl, pr = points[:m], points[m:]
key, rkey = keys[axis], keys[not axis]
ans = min(solve(sorted(pl, key=rkey), not axis),
solve(sorted(pr, key=rkey), not axis))
pm = key(pr[0])
for p in reversed(pl):
if key(p) <= pm - ans:
break
for q in pr:
if key(q) >= pm + ans:
break
rp = rkey(p)
if rp - ans < rkey(q) < rp + ans:
ans = min(ans, abs(q - p))
return ans
n = int(input())
points = [complex(*map(float, input().split())) for _ in range(n)]
print(solve(sorted(points, key=keys[0]), 0)) | Traceback (most recent call last):
File "/tmp/tmpou_kdcsq/tmpr5zutv1h.py", line 29, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s401015495 | p02303 | u797673668 | 1492589429 | Python | Python3 | py | Runtime Error | 30 | 7756 | 924 | import sys
sys.setrecursionlimit(10000)
from operator import attrgetter
from itertools import combinations
keys = [attrgetter('real'), attrgetter('imag')]
def solve(points, axis):
l = len(points)
if l < 20:
return min(abs(p2 - p1) for p1, p2 in combinations(points, 2))
m = n // 2
pl, pr = points[:m], points[m:]
key, rkey = keys[axis], keys[not axis]
ans = min(solve(sorted(pl, key=rkey), not axis),
solve(sorted(pr, key=rkey), not axis))
pm = key(pr[0])
for p in reversed(pl):
if key(p) <= pm - ans:
break
for q in pr:
if key(q) >= pm + ans:
break
rp = rkey(p)
if rp - ans < rkey(q) < rp + ans:
ans = min(ans, abs(q - p))
return ans
n = int(input())
points = [complex(*map(float, input().split())) for _ in range(n)]
print(solve(sorted(points, key=keys[0]), 0)) | Traceback (most recent call last):
File "/tmp/tmpdwcnuslv/tmp3008ltvm.py", line 33, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s586227548 | p02303 | u928329738 | 1512309233 | Python | Python3 | py | Runtime Error | 0 | 0 | 310 | import numpy as np
n = int(input())
p = []
for i in range(n):
p.append(tuple(map(float,input().split())))
d = []
min = 999999999999
for i in range(n-1):
for j in range(i+1,n):
a = ((p[j][0]-p[i][0])**2+(p[j][1]-p[i][1])**2)
if a < min:
min = a
print(round(np.sqrt(min),11)) | Traceback (most recent call last):
File "/tmp/tmpsjjwsa2b/tmpc9hu524d.py", line 2, in <module>
n = int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s365542492 | p02304 | u629780968 | 1546487871 | Python | Python3 | py | Runtime Error | 40 | 6348 | 3367 | from enum import IntEnum
class Action(IntEnum):
ADD = 1
SEARCH = 2
REMOVE = 3
class Color(IntEnum):
BLACK=0
RED=1
@staticmethod
def flip(c):
return [Color.RED,Color.BLACK][c.value]
class Node:
__slots__ = ('value','left','right','color','valid')
def __init__(self,value):
self.value=value
self.left=Leaf
self.right=Leaf
self.color=Color.RED
self.valid=True
def flip_color(self):
self.color==Color.RED
def is_red(self):
return self.color == Color.RED
def __str__(self):
return ('('+str(self.left)+','+str(self.value)+','+str(self.right)+')')
class LeafNode(Node):
def __init__(self):
self.value=None
self.left=None
self.right=None
self.color=None
self.valid=False
def flip_color(self):
pass
def is_red(self):
return False
def __str__(self):
return 'Leaf'
Leaf=LeafNode()
class RedBlackBST:
def __init__(self):
self.root=Leaf
def add(self,value):
def _add(node):
if node is Leaf:
node=Node(value)
if node.value>value:
node.left=_add(node.right)
elif node.value<value:
node.right=_add(node.right)
else:
if not node.valid:
node.valid=True
node=self._balance(node)
return node
self.root=_add(self.root)
self.root.color=Color.BLACK
def _balance(self,node):
if node.right.is_red() and not node.left.is_red():
node=self._rotate_left(node)
if node.left.is_red() and node.left.left.is_red():
node=self._rotate_right(node)
if node.left.is_red() and node.right.is_red():
node = self._flip_colors(node)
return node
def _rotate_left(self,node):
x=node.right
node.right=x.left
x.left=node
x.color=node.color
node.color=Color.RED
return x
def _rotate_right(self,node):
x=node.left
node.left=x.right
x.right=node
x.color=node.color
node.color=Color.RED
return x
def _flip_colors(self,node):
node.flip_color()
node.left.flip_color()
node.right.flip_color()
return node
def remove(self,value):
def _remove(node):
if node is Leaf:
return
if node.value>value:
_remove(node.left)
elif node.value<value:
_remove(node.right)
else:
node.valid=False
_remove(self.root)
def count(self,min_,max_):
def _range(node):
if node is Leaf:
return 0
if node.value>max_:
return _range(node.left)
elif node.value<min_:
return _range(node.right)
else:
count= _range(node.left)+_range(node.right)
if node.valid:
count+=1
return count
return _range(self.root)
def __str__(self):
return str(self.root)
def count_intersections(segments):
segments.sort()
tree=RedBlackBST()
count=0
for seg in segments:
x,action,y=seg
if action==Action.SEARCH:
count+=tree.count(*y)
elif action==Action.ADD:
tree.add(y)
elif action == Action.REMOVE:
tree.remove(y)
return count
n=int(input())
segs=[]
for i in range(n):
x1,y1,x2,y2=map(int,input().split())
if x1>x2 or y1>y2:
x1,x2=x2,x1
y1,y2=y2,y1
if x1==x2:
segs.append((x1,Action.SEARCH,(y1,y2)))
else:
segs.append((x1,Action.ADD,y1))
segs.append((x2,Action.REMOVE,y2))
print(count_intersections(segs))
| Traceback (most recent call last):
File "/tmp/tmpg896kvhl/tmpks_0oual.py", line 150, in <module>
n=int(input())
^^^^^^^
EOFError: EOF when reading a line
| |
s438916365 | p02304 | u011621222 | 1526486091 | Python | Python3 | py | Runtime Error | 0 | 0 | 3155 | lass AvlTree(BinarySearchTree):
'''An extension t the BinarySearchTree data structure which
strives to keep itself balanced '''
def _put(self,key,val,currentNode):
if key < currentNode.key:
if current.Node.hasLeftChild():
self._put(key,val,currentNode.leftChild)
else:
currentNode.leftChild = TreeNode(key,val,parent=currentNode)
self.updateBalance(currentNode.leftChile)
else:
if currentNode.hasRightChild():
self._put(key,val,currentNode.rightChild)
else:
currentNode.rightChild = TreeNode(key,val,parent=currentNode)
self.updateBalance(currentNode.rightChild)
def updateBalance(self,node):
if node.balanceFactor > 1 or node.balanceFactor < -1:
self.rebalance(node)
return
if node.parent != None:
if node.isLeftChild():
node.parent.balancefactor += 1
elif node.isRightChild():
node.parent.balanceFactor -= 1
if node.parent.balanceFactor != 0:
self.updateBalance(node.parent)
def rotateLeft(self,rotRoot):
newRoot = rotRoot.rightChild
rotRoot.rightChild = newRoot.leftChild
if newRoot.leftChild != None:
newRoot.leftChild.parent = rotRoot
newRoot.parent = rotRoot.parent
if rotRoot.isRoot():
self.root = newRoot
else:
if rotRoot.isLeftChild():
rotRoot.parent.leftChild = newRoot
else:
rotRoot.parent.rightChild = newRoot
newRoot.leftChild = rotRoot
rotRoot.parent = newRoot
rotRoot.balanceFactor = rotRoot.balanceFactor + 1 - min(
newRoot.balanceFactor, 0)
newRoot.balanceFactor = newRoot.blanceFactor + 1 + max(
rotRoot.balanceFactor, 0)
def rotateRight(self,rotRoot):
newRoot = rotRoot.leftChild
rotRoot.leftChild = newRoot.rightChild
if newRoot.rightChild != None:
newRoot.rightChild.parent = rotRoot
newRoot.parent = rotRoot.parent
if rotRoot.isRoot():
self.root = newRoot
else:
if rotRoot.isRightChild():
rotRoot.parent.rightChild = newRoot
# leftchild??????
newRoot.rightChild = rotRoot
rotRoot.parent = newRoot
rotRoot.balanceFactor = rotRoot.balanceFactor + 1 - min(
newRoot.balanceFactor, 0)
newRoot.balanceFactor = newRoot.balanceFactor + 1 + max(
rotRoot.balanceFactor, 0)
def rebalance(self,node):
if node.balanceFactor < 0:
if node.rightChild.balanceFactor > 0:
self.rotateRight(node.rightChild)
self.rotateLeft(node)
else:
self.rotateLeft(node)
elif node.balanceFactor > 0:
if node.leftChild.balanceFactor < 0:
self.rotateLeft(node.leftchilc)
self.rotateRight(node)
else:
self.rotateRight(node)
| File "/tmp/tmpxvp7fwhv/tmpzbvhux0v.py", line 1
lass AvlTree(BinarySearchTree):
^^^^^^^
SyntaxError: invalid syntax
| |
s373101074 | p02305 | u265136581 | 1523264165 | Python | Python3 | py | Runtime Error | 0 | 0 | 488 |
cx1, cy1, r1 = map(float, raw_input().split())
cx2, cy2, r2 = map(float, raw_input().split())
import math
distance = math.sqrt( math.pow(cx1-cx2, 2) + math.pow(cy1-cy2, 2) )
rsum = r1 + r2
rmax = math.max(r1, r2)
rmin = math.min(r1, r2)
import sys
if distance > rsum:
print(4)
elif abs(distance - rsum) < sys.float_info.epsilon:
print(3)
else:
if rmax < distance + rmin:
print(2)
elif abs(rmax - distance - rmin) < sys.float_info.epsilon:
print(1)
else:
print(0)
| Traceback (most recent call last):
File "/tmp/tmp_fnpi9d3/tmpiltmbjbq.py", line 2, in <module>
cx1, cy1, r1 = map(float, raw_input().split())
^^^^^^^^^
NameError: name 'raw_input' is not defined
| |
s216292788 | p02305 | u825008385 | 1523809516 | Python | Python3 | py | Runtime Error | 0 | 0 | 3819 | # Single Source Shortest Path
class node():
def __init__(self, v, cost):
self.v = v
self.cost = cost
infty = 999999999
dict_c = {}
[vertex, edge, r] = list(map(int, input("").split()))
root_c = [node(r, 0)]
final_c = [infty for i in range(vertex)]
final_c[r] = 0
for i in range(edge):
[e1, e2, c] = list(map(int, input("").split()))
if e1 == r:
root_c.append(node(e2, c))
final_c[e2] = c
else:
dict_c[(e1, e2)] = c
def min_heap(i):
global root_c
l = 2*i
r = 2*i + 1
if l <= len(root_c) - 1 and root_c[l].cost <= root_c[i].cost:
if root_c[l].cost < root_c[i].cost:
min = l
elif root_c[l].v < root_c[i].v:
min = l
else:
min = i
else:
min = i
if r <= len(root_c) - 1 and root_c[r].cost <= root_c[min].cost:
if root_c[r].cost < root_c[min].cost:
min = r
elif root_c[r].v < root_c[min].v:
min = r
#else:
if min != i:
root_c[i], root_c[min] = root_c[min], root_c[i]
min_heap(min)
def build_min_heap():
global root_c
length = len(root_c) - 1
for i in range(int(length/2), 0, -1):
min_heap(i)
def extract_min():
global root_c
min = root_c[1]
#print("min_cost ", root_c[1].cost, root_c[2].cost, root_c[3].cost, root_c[4].cost, root_c[5].cost, root_c[6].cost, root_c[7].cost)
#print("min_vertex", root_c[1].v, root_c[2].v, root_c[3].v, root_c[4].v, root_c[5].v, root_c[6].v, root_c[7].v)
root_c[1] = root_c[len(root_c) - 1]
#print("1: ",root_c[1].cost, root_c[1].v)
del root_c[len(root_c) - 1]
min_heap(1)
#print("min_cost 2", root_c[1].cost, root_c[2].cost, root_c[3].cost, root_c[4].cost, root_c[5].cost, root_c[6].cost)
#print("min_vertex2", root_c[1].v, root_c[2].v, root_c[3].v, root_c[4].v, root_c[5].v, root_c[6].v)
#print("length: ",len(root_c))
return min
def decrease_key(i, c):
global root_c
root_c[i].cost = c
while i > 1 and root_c[int(i/2)].cost >= root_c[i].cost:
if root_c[int(i/2)].cost > root_c[i].cost:
root_c[int(i/2)], root_c[i] = root_c[i], root_c[int(i/2)]
elif root_c[int(i/2)].v > root_c[i].v:
root_c[int(i/2)], root_c[i] = root_c[i], root_c[int(i/2)]
else:
root_c[int(i/2)], root_c[i] = root_c[int(i/2)], root_c[i]
i = int(i/2)
def min_insert(v, c):
global infty, root_c
for i in range(1, len(root_c)):
if root_c[i].v == v:
decrease_key(i,c)
return
root_c.append(node(v, infty))
decrease_key(len(root_c) - 1, c)
def Dijkstra(root, n):
count = 1
global infty, dict_c, root_c, final_c
label = [i for i in range(n)]
#print(count, label[root], final_c[label[root]])
count += 1
del label[root]
while len(label) != 0:
if len(root_c) > 1:
min_node = extract_min()
else:
break
for i in range(len(label)):
if min_node.v == label[i]:
delete_label = i
continue
if ((min_node.v, label[i]) in dict_c.keys()) == True:
if final_c[label[i]] > final_c[min_node.v] + dict_c[(min_node.v, label[i])]:
final_c[label[i]] = final_c[min_node.v] + dict_c[(min_node.v, label[i])]
min_insert(label[i], final_c[label[i]])
#print(count, label[delete_label], final_c[label[delete_label]])
count += 1
del label[delete_label]
build_min_heap()
'''
print("root_c :")
for i in range(len(root_c)):
print(root_c[i].cost)
print("\n")
'''
Dijkstra(r, vertex)
#print("\n")
for i in range(vertex):
if final_c[i] == infty:
print("INF")
else:
print(final_c[i])
| Traceback (most recent call last):
File "/tmp/tmpoehahfch/tmprpm9g7di.py", line 9, in <module>
[vertex, edge, r] = list(map(int, input("").split()))
^^^^^^^^^
EOFError: EOF when reading a line
| |
s888419766 | p02305 | u893844544 | 1523843446 | Python | Python3 | py | Runtime Error | 0 | 0 | 290 | c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]
d = math.sqrt(pow(c1x-c2x, 2) + pow(c1y-c2y, 2))
s = c1r + c2r
if d > s:
print 4
else if d == c:
print 3
else if d > 2*s:
print 2
else if d == 2*s:
print 1
else:
print 0
| File "/tmp/tmpt2wn5k48/tmpili22orh.py", line 9
print 4
^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
| |
s208727312 | p02305 | u893844544 | 1523843610 | Python | Python3 | py | Runtime Error | 0 | 0 | 295 | c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]
d = math.sqrt(pow(c1x-c2x, 2) + pow(c1y-c2y, 2))
s = c1r + c2r
if d > s:
print(4)
else if d == c:
print(3)
else if d > 2*s:
print(2)
else if d == 2*s:
print(1)
else:
print(0)
| File "/tmp/tmp99oo27oa/tmpvehiw6d8.py", line 10
else if d == c:
^^
SyntaxError: expected ':'
| |
s570427412 | p02305 | u893844544 | 1523843659 | Python | Python3 | py | Runtime Error | 0 | 0 | 286 | c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]
d = math.sqrt(pow(c1x-c2x, 2) + pow(c1y-c2y, 2))
s = c1r + c2r
if d > s:
print(4)
elif d == c:
print(3)
elif d > 2*s:
print(2)
elif d == 2*s:
print(1)
else:
print(0)
| Traceback (most recent call last):
File "/tmp/tmpypmfzl5x/tmpj3ne68bz.py", line 1, in <module>
c1x,c1y,c1r = [int(i) for i in input().split()]
^^^^^^^
EOFError: EOF when reading a line
| |
s004096707 | p02305 | u893844544 | 1523843751 | Python | Python3 | py | Runtime Error | 20 | 5668 | 299 | import math
c1x,c1y,c1r = [int(i) for i in input().split()]
c2x,c2y,c2r = [int(i) for i in input().split()]
d = math.sqrt(pow(c1x-c2x, 2) + pow(c1y-c2y, 2))
s = c1r + c2r
if d > s:
print(4)
elif d == c:
print(3)
elif d > 2*s:
print(2)
elif d == 2*s:
print(1)
else:
print(0)
| Traceback (most recent call last):
File "/tmp/tmp6hf07r_f/tmpn8kvyx5y.py", line 3, in <module>
c1x,c1y,c1r = [int(i) for i in input().split()]
^^^^^^^
EOFError: EOF when reading a line
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.