s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1 value | original_language stringclasses 11 values | filename_ext stringclasses 1 value | status stringclasses 1 value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s041607742 | p00207 | u227162786 | 1490018860 | Python | Python3 | py | Runtime Error | 0 | 0 | 1085 | def dfs(x, y, m, v, W, H, xg, yg):
'''
'''
v[y][x] = True
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx = x + dx
ny = y + dy
if nx in range(W) and ny in range(H) and m[ny][nx] == m[y][x] and v[ny][nx] == False:
dfs(nx, ny, m, v, W, H, xg, yg)
while True:
H, W = list(map(int, input().split()))
if H == 0 and W == 0:
break
xs, ys = list(map(lambda x: int(x)-1, input().split()))
xg, yg = list(map(lambda x: int(x)-1, input().split()))
n = int(input())
m = [[0 for _ in range(W)] for __ in range(H)]
v = [[False for _ in range(W)] for __ in range(H)]
for _ in range(n):
c, d, x, y = list(map(int, input().split()))
x -= 1
y -= 1
if d == 0:
for y in range(2):
for x in range(4):
m[y][x] = c
else:
for y in range(4):
for x in range(2):
m[y][x] = c
dfs(xs, ys, m, v, W, H, xg, yg)
if v[yg][xg]:
print('OK')
else:
print('NG') |
s092698653 | p00207 | u227162786 | 1490019105 | Python | Python3 | py | Runtime Error | 0 | 0 | 1216 | def dfs(x, y, m, v, W, H, xg, yg):
'''
'''
v[y][x] = True
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
nx = x + dx
ny = y + dy
if nx in range(W) and ny in range(H) and m[ny][nx] == m[y][x] and v[ny][nx] == False:
dfs(nx, ny, m, v, W, H, xg, yg)
if __name__ == '__main__':
while True:
H, W = list(map(int, input().split()))
if H == 0 and W == 0:
break
xs, ys = list(map(lambda x: int(x)-1, input().split()))
xg, yg = list(map(lambda x: int(x)-1, input().split()))
n = int(input())
m = [[0 for _ in range(W)] for __ in range(H)]
v = [[False for _ in range(W)] for __ in range(H)]
for _ in range(n):
c, d, x, y = list(map(int, input().split()))
x -= 1
y -= 1
if d == 0:
for y in range(2):
for x in range(4):
m[y][x] = c
else:
for y in range(4):
for x in range(2):
m[y][x] = c
dfs(xs, ys, m, v, W, H, xg, yg)
if v[yg][xg]:
print('OK')
else:
print('NG') |
s090657938 | p00207 | u510797278 | 1504579063 | Python | Python3 | py | Runtime Error | 0 | 0 | 1349 | BLOCK_WIDTH = 4
BLOCK_HEIGHT = 2
field = []
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
w = 0
h = 0
xg = 0
yg = 0
def main():
global field, w, h, xg, yg
while True:
w, h = map(int, input().split())
if w == 0 and h == 0:
break
xs, ys = map(int, input().split())
xg, yg = map(int, input().split())
n = int(input())
field = [[0] * w for _ in range(h)]
for i in range(n):
c, d, x, y = map(int, input().split())
arrangement(c, d, x, y)
if dfs(field[xs][ys], xs, ys):
print("OK")
else:
print("NG")
def arrangement(c, d, x, y):
global field
if d == 0:
for i in range(BLOCK_HEIGHT):
for j in range(BLOCK_WIDTH):
field[y + i][x + j] = c
else:
for i in range(BLOCK_WIDTH):
for j in range(BLOCK_HEIGHT):
field[y + i][x + j] = c
def dfs(c, x, y):
global field
if x < 0 or x >= w or y < 0 or y >= h:
return False
if field[y][x] != c:
return False
if x == xg and y == yg:
return True
field[y][x] = -1
for i in range(4):
next_x = x + dx[i]
next_y = y + dy[i]
if dfs(c, next_x, next_y):
return True
return False
if __name__ == '__main__':
main() |
s408923606 | p00207 | u510797278 | 1504582808 | Python | Python3 | py | Runtime Error | 0 | 0 | 1349 | BLOCK_WIDTH = 4
BLOCK_HEIGHT = 2
field = []
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
w = 0
h = 0
xg = 0
yg = 0
def main():
global field, w, h, xg, yg
while True:
w, h = map(int, input().split())
if w == 0 and h == 0:
break
xs, ys = map(int, input().split())
xg, yg = map(int, input().split())
n = int(input())
field = [[0] * w for _ in range(h)]
for i in range(n):
c, d, x, y = map(int, input().split())
arrangement(c, d, x, y)
if dfs(field[ys][xs], xs, ys):
print("OK")
else:
print("NG")
def arrangement(c, d, x, y):
global field
if d == 0:
for i in range(BLOCK_HEIGHT):
for j in range(BLOCK_WIDTH):
field[y + i][x + j] = c
else:
for i in range(BLOCK_WIDTH):
for j in range(BLOCK_HEIGHT):
field[y + i][x + j] = c
def dfs(c, x, y):
global field
if x < 0 or x >= w or y < 0 or y >= h:
return False
if field[y][x] != c:
return False
if x == xg and y == yg:
return True
field[y][x] = -1
for i in range(4):
next_x = x + dx[i]
next_y = y + dy[i]
if dfs(c, next_x, next_y):
return True
return False
if __name__ == '__main__':
main() |
s789657511 | p00207 | u510797278 | 1504589441 | Python | Python3 | py | Runtime Error | 0 | 0 | 1359 | BLOCK_WIDTH = 4
BLOCK_HEIGHT = 2
field = []
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
w = 0
h = 0
xg = 0
yg = 0
def main():
global field, w, h, xg, yg
while True:
w, h = map(int, input().split())
if w == 0 and h == 0:
break
xs, ys = map(int, input().split())
xg, yg = map(int, input().split())
n = int(input())
field = [[0] * w for _ in range(h)]
for i in range(n):
c, d, x, y = map(int, input().split())
arrangement(c, d, x, y)
if dfs(field[ys][xs], xs, ys):
print("OK")
else:
print("NG")
def arrangement(c, d, x, y):
global field
if d == 0:
[[draw(x + j, y + i, c) for j in range(BLOCK_WIDTH)] for i in range(BLOCK_HEIGHT)]
else:
[[draw(x + j, y + i, c) for j in range(BLOCK_HEIGHT)] for i in range(BLOCK_WIDTH)]
def draw(x, y, c):
field[y][x] = c
def dfs(c, x, y):
global field
if x == xg and y == yg:
return True
field[y][x] = -1
for i in range(4):
next_x = x + dx[i]
next_y = y + dy[i]
if next_x < 0 or next_x >= w or next_y < 0 or next_y >= h:
continue
if field[next_y][next_x] == c:
if dfs(c, next_x, next_y):
return True
return False
if __name__ == '__main__':
main() |
s983644866 | p00207 | u633068244 | 1398939558 | Python | Python | py | Runtime Error | 0 | 0 | 84 | B[y][x] = -1
check(B,x-1,y,c);check(B,x,y-1,c);check(B,x+1,y,c);check(B,x,y+1,c) |
s802672130 | p00207 | u633068244 | 1398939570 | Python | Python | py | Runtime Error | 0 | 0 | 641 | global B
def check(B,x,y,c):
if 0 < x < w+2 and 0 < y < h+2 and B[y][x] == c:
B[y][x] = -1
check(B,x-1,y,c);check(B,x,y-1,c);check(B,x+1,y,c);check(B,x,y+1,c)
while 1:
w,h = map(int,raw_input().split())
if w == 0: break
B = [[0]*(w+2) for i in range(h+2)]
xs,ys = map(int,raw_input().split())
xg,yg = map(int,raw_input().split())
for i in range(input()):
c,d,x,y = map(int,raw_input().split())
if d == 0:
B[y][x:x+4] = [c]*4
B[y+1][x:x+4] = [c]*4
else:
for j in range(4):
B[y+j][x:x+2] = [c]*2
if B[ys][xs] != B[yg][xg]:
print "NG"
else:
check(B,xs,ys,B[xs][ys])
print "OK" if B[yg][xg] == -1 else "NG" |
s700452548 | p00207 | u633068244 | 1398939596 | Python | Python | py | Runtime Error | 0 | 0 | 641 | global B
def check(B,x,y,c):
if 0 < x < w+2 and 0 < y < h+2 and B[y][x] == c:
B[y][x] = -1
check(B,x-1,y,c);check(B,x,y-1,c);check(B,x+1,y,c);check(B,x,y+1,c)
while 1:
w,h = map(int,raw_input().split())
if w == 0: break
B = [[0]*(w+2) for i in range(h+2)]
xs,ys = map(int,raw_input().split())
xg,yg = map(int,raw_input().split())
for i in range(input()):
c,d,x,y = map(int,raw_input().split())
if d == 0:
B[y][x:x+4] = [c]*4
B[y+1][x:x+4] = [c]*4
else:
for j in range(4):
B[y+j][x:x+2] = [c]*2
if B[ys][xs] != B[yg][xg]:
print "NG"
else:
check(B,xs,ys,B[xs][ys])
print "OK" if B[yg][xg] == -1 else "NG" |
s165896795 | p00208 | u566872786 | 1512379166 | Python | Python3 | py | Runtime Error | 0 | 0 | 67 | while(1):print(oct(n)[2:].translate(str.maketrans('4567', '5789'))) |
s656682715 | p00208 | u531592024 | 1528988557 | Python | Python3 | py | Runtime Error | 0 | 0 | 282 | def ge(arr):
for i in range(len(arr)):
tmp = int(arr[i])
if tmp >= 4:
tmp += 1
if tmp >= 6:
tmp += 1
arr[i] = str(tmp)
while True:
n = int(input)
if n == 0:
break
print("".join(ge(list(oct(n))[2:])))
|
s775166019 | p00208 | u870370075 | 1389355786 | Python | Python | py | Runtime Error | 0 | 0 | 700 | inputlist=[]
while 1:
inputnum=int(raw_input())
if(inputnum==0):break
inputlist.append(inputnum)
def octnpower(num):
flag=0
maxi=0
maxj=0
if(num<8):
temp[0]=num
return
for i in range(1,11):
for j in range(1,8):
if(num>=(8**i)*j):
flag=(8**i)*j
maxi=i
maxj=j
else:
temp[maxi]=maxj
return octnpower(num-flag)
octdictionary={0:0,1:1,2:2,3:3,4:5,5:7,6:8,7:9}
for i in range(len(inputlist)-1):
temp=[0]*10
octnpower(inputlist[i])
for i in range(len(temp)):
temp[i]=octdictionary[temp[i]]
temp.reverse()
for j in range(len(temp)):
index=j
if(temp[j]!=0):break
temp=temp[index:]
ansstr=""
for j in range(len(temp)):
ansstr+=str(temp[i])
print ansstr |
s080357072 | p00209 | u633068244 | 1399116113 | Python | Python | py | Runtime Error | 0 | 0 | 776 | while 1:
n,m = map(int,raw_input().split())
if n == 0: break
scene = [map(int,raw_input().split()) for i in range(n)]
pic = [map(int,raw_input().split()) for i in range(m)]
ans = "NA"
for rot in range(4):
for y in range(n-m):
for x in range(n-m):
flag = 0
for dy in range(m):
for dx in range(m):
if pic[dy][dx] > -1 and scene[y+dy][x+dx] - pic[dy][dx] != 0:
flag = 1
break
if flag == 1: break
if flag == 0:
flag1 = 0
for dy in range(m):
for dx in range(m):
if pic[dy][dx] > -1:
ans = str(x+dx+1)+" "+str(y+dy+1)
flag1 = 1
break
if flag1 == 1: break
if flag == 0: break
if flag == 0: break
pic = [[pic[j][i] for j in range(m-1,-1,-1)] for i in range(m)]
print ans |
s461542242 | p00209 | u633068244 | 1399116320 | Python | Python | py | Runtime Error | 0 | 0 | 832 | def getxy(pic):
flag = 0
for dy in range(m):
for dx in range(m):
if pic[dy][dx] > -1:
ans = str(x+dx+1)+" "+str(y+dy+1)
flag = 1
break
if flag == 1: break
return ans
while 1:
n,m = map(int,raw_input().split())
if n == 0: break
scene = [map(int,raw_input().split()) for i in range(n)]
pic = [map(int,raw_input().split()) for i in range(m)]
ans = "NA"
for rot in range(4):
if scene == pic:
ans = getxy(pic)
for y in range(n-m):
for x in range(n-m):
flag = 0
for dy in range(m):
for dx in range(m):
if pic[dy][dx] > -1 and scene[y+dy][x+dx] - pic[dy][dx] != 0:
flag = 1
break
if flag == 1: break
if flag == 0:
ans = getxy(pic)
if flag == 0: break
if flag == 0: break
pic = [[pic[j][i] for j in range(m-1,-1,-1)] for i in range(m)]
print ans |
s804027091 | p00210 | u858885710 | 1404010356 | Python | Python | py | Runtime Error | 0 | 0 | 1877 | direction = {'N' : 0, 'E' : 1, 'S' : 2, 'W' : 3}
step = [(-1, 0), (0, 1), (1, 0), (0, -1)]
while True:
W, H = map(int, raw_input().split())
if W == 0 and H == 0: break
m = [None] * H
for i in xrange(H):
m[i] = list(raw_input())
people = []
for i in xrange(H):
for j in xrange(W):
if m[i][j] in "NESW":
people.append( (i, j, direction[m[i][j]]) )
time = 0
while any(people):
time += 1
if time > 180:
time = -1
break
sched = []
for n in xrange(len(people)):
if people[n] is None: continue
x, y, d = people[n]
for i in range(1, -3, -1):
dx, dy = step[(d+i+4)%4]
if 0 <= x+dx < H and 0 <= y+dy < W and m[x + dx][y + dy] in "X.":
beat = True
for k in range(len(sched)):
xx, yy, dd = sched[k][1:]
if (x+dx, y+dy) == (xx, yy):
if dd%4 < (d+i+4)%4:
sched[k] = ( n, x+dx, y+dy, (d+i+4)%4 )
beat = False
break
else:
beat = False
break
if beat:
sched.append( ( n, x+dx, y+dy, (d+i+4)%4 ) )
break
for (k, x, y, d) in sched:
m[ people[k][0] ][ people[k][1] ] = '.'
if m[x][y] == 'X':
people[k] = None
else:
m[x][y] = 'H'
people[k] = x, y, d
for d in m:
for c in d:
print c,
print ''
print ''
if time > 0:
print time
else:
print 'NA'
|
s537808120 | p00210 | u858885710 | 1404017337 | Python | Python | py | Runtime Error | 0 | 0 | 1772 | direction = {'N' : 0, 'E' : 1, 'S' : 2, 'W' : 3}
step = [( -1, 0 ), ( 0, 1 ), ( 1, 0 ), ( 0, -1 )]
while True:
W, H = map( int, raw_input().split() )
if W == 0 and H == 0: break
m = [ list( raw_input().split() ) for i in xrange( H ) ]
people = [ ( i, j, direction[ m[i][j] ] ) for i in xrange( H ) for j in range( W )
if m[i][j] in "NESW" ]
time = 0
while any( people ):
time += 1
if time > 180:
time = -1
break
sched = []
for n in xrange( len( people ) ):
if people[n] is None: continue
x, y, d = people[n]
for i in range(1, -3, -1):
dx, dy = step[(d + i) % 4]
if 0 <= x+dx < H and 0 <= y+dy < W and m[x+dx][y+dy] in "X.":
beat = True
for k in range( len( sched ) ):
xx, yy, dd = sched[k][1:]
if ( x+dx, y+dy ) == ( xx, yy ):
if dd < (d + i) % 4:
sched[k] = ( n, x+dx, y+dy, (d + i) % 4 )
beat = False
break
else:
beat = False
break
if beat:
sched.append( ( n, x+dx, y+dy, (d + i) % 4 ) )
break
for ( k, x, y, d ) in sched:
m[ people[k][0] ][ people[k][1] ] = '.'
if m[x][y] == 'X':
people[k] = None
else:
m[x][y] = 'H'
people[k] = x, y, d
if time > 0:
print time
else:
print 'NA' |
s016028281 | p00210 | u858885710 | 1404022377 | Python | Python | py | Runtime Error | 0 | 0 | 1907 | import sys
direction = {'N' : 0, 'E' : 1, 'S' : 2, 'W' : 3}
step = [( -1, 0 ), ( 0, 1 ), ( 1, 0 ), ( 0, -1 )]
vv = []
while True:
W, H = map( int, sys.stdin.readline().rstrip().split() )
if W == 0 and H == 0: break
m = [ list( sys.stdin.readline().strip() ) for i in xrange( H ) ]
people = [ ( i, j, direction[ m[i][j] ] ) for i in xrange( H ) for j in range( W )
if m[i][j] in "NESW" ]
time = 0
while any( people ):
time += 1
if time > 180:
time = -1
break
sched = []
for n in xrange( len( people ) ):
if people[n] is None: continue
x, y, d = people[n]
for i in range(1, -3, -1):
dx, dy = step[(d + i) % 4]
if 0 <= x+dx < H and 0 <= y+dy < W and m[x+dx][y+dy] in "X.":
people[n][2] = (d + i) % 4
beat = True
for k in range( len( sched ) ):
xx, yy, dd = sched[k][1:]
if ( x+dx, y+dy ) == ( xx, yy ):
if dd < (d + i) % 4:
sched[k] = ( n, x+dx, y+dy, (d + i) % 4 )
beat = False
break
else:
beat = False
break
if beat:
sched.append( ( n, x+dx, y+dy, (d + i) % 4 ) )
break
for ( k, x, y, d ) in sched:
m[ people[k][0] ][ people[k][1] ] = '.'
if m[x][y] == 'X':
people[k] = None
else:
m[x][y] = 'H'
people[k] = x, y, d
if time >= 0:
vv.append(time)
else:
vv.append('NA')
for v in vv:
print v |
s535338685 | p00210 | u673933691 | 1404029626 | Python | Python | py | Runtime Error | 0 | 0 | 4995 | import copy
def hinan():
ans = []
while True:
n = raw_input().split(" ")
if n == ["0" ,"0"]:
for an in ans:
print an
break
elif len(n) == 2:
xs = []
k = int(n[1])
for m in range(k):
n = map(str,raw_input())
xs.append(n)
for time in range(181):
check = []
for i in range(len(xs)):
if not any(x in xs[i] for x in ["W","E","N","S"]):
check.append(True)
continue
else:
check.append(False)
for j in range(len(xs[i])):
if xs[i][j] == "S":
if xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j] == "W":
if xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i][j] == "E":
if xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i][j] == "N":
if xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
ys = copy.deepcopy(xs)
if all(check):
ans.append(time)
break
for i in range(len(xs)):
for j in range(len(xs[i])):
if xs[i][j] == "S":
if xs[i + 1][j + 1] != "W":
if xs[i + 1][j] == "X":
ys[i][j] = "."
continue
else:
ys[i + 1][j] ,ys[i][j] = "S" ,"."
continue
elif xs[i][j] == "E":
if j < len(xs[i]) - 2:
if xs[i][j + 2] != "W" and xs[i - 1][j + 1] != "S":
if xs[i][j + 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j + 1] ,ys[i][j] = "E" ,"."
continue
else:
if xs[i][j + 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j + 1] ,ys[i][j] = "E" ,"."
continue
elif xs[i][j] == "W":
if xs[i][j - 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j - 1] ,ys[i][j] = "W" ,"."
continue
elif xs[i][j] == "N":
if xs[i - 1][j + 1] != "W" and xs[i - 2][j] != "S" and xs[i - 1][j - 1] != "E":
if xs[i - 1][j] == "X":
ys[i][j] = "."
continue
elif xs[i - 1][j] == ".":
ys[i - 1][j] ,ys[i][j] = "N" ,"."
continue
xs = ys
else:
ans.append("NA")
hinan() |
s909267724 | p00210 | u673933691 | 1404029800 | Python | Python | py | Runtime Error | 0 | 0 | 4995 | import copy
def hinan():
ans = []
while True:
n = raw_input().split(" ")
if n == ["0" ,"0"]:
for an in ans:
print an
break
elif len(n) == 2:
xs = []
k = int(n[1])
for m in range(k):
n = map(str,raw_input())
xs.append(n)
for time in range(181):
check = []
for i in range(len(xs)):
if not any(x in xs[i] for x in ["W","E","N","S"]):
check.append(True)
continue
else:
check.append(False)
for j in range(len(xs[i])):
if xs[i][j] == "S":
if xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j] == "W":
if xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i][j] == "E":
if xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i][j] == "N":
if xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
ys = copy.deepcopy(xs)
if all(check):
ans.append(time)
break
for i in range(len(xs)):
for j in range(len(xs[i])):
if xs[i][j] == "S":
if xs[i + 1][j + 1] != "W":
if xs[i + 1][j] == "X":
ys[i][j] = "."
continue
else:
ys[i + 1][j] ,ys[i][j] = "S" ,"."
continue
elif xs[i][j] == "E":
if j < len(xs[i]) - 2:
if xs[i][j + 2] != "W" and xs[i - 1][j + 1] != "S":
if xs[i][j + 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j + 1] ,ys[i][j] = "E" ,"."
continue
else:
if xs[i][j + 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j + 1] ,ys[i][j] = "E" ,"."
continue
elif xs[i][j] == "W":
if xs[i][j - 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j - 1] ,ys[i][j] = "W" ,"."
continue
elif xs[i][j] == "N":
if xs[i - 1][j + 1] != "W" and xs[i - 2][j] != "S" and xs[i - 1][j - 1] != "E":
if xs[i - 1][j] == "X":
ys[i][j] = "."
continue
elif xs[i - 1][j] == ".":
ys[i - 1][j] ,ys[i][j] = "N" ,"."
continue
xs = ys
else:
ans.append("NA")
hinan() |
s730907477 | p00210 | u673933691 | 1404029861 | Python | Python | py | Runtime Error | 0 | 0 | 4995 | import copy
def hinan():
ans = []
while True:
n = raw_input().split(" ")
if n == ["0" ,"0"]:
for an in ans:
print an
break
elif len(n) == 2:
xs = []
k = int(n[1])
for m in range(k):
n = map(str,raw_input())
xs.append(n)
for time in range(181):
check = []
for i in range(len(xs)):
if not any(x in xs[i] for x in ["W","E","N","S"]):
check.append(True)
continue
else:
check.append(False)
for j in range(len(xs[i])):
if xs[i][j] == "S":
if xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j] == "W":
if xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i][j] == "E":
if xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i][j] == "N":
if xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
ys = copy.deepcopy(xs)
if all(check):
ans.append(time)
break
for i in range(len(xs)):
for j in range(len(xs[i])):
if xs[i][j] == "S":
if xs[i + 1][j + 1] != "W":
if xs[i + 1][j] == "X":
ys[i][j] = "."
continue
else:
ys[i + 1][j] ,ys[i][j] = "S" ,"."
continue
elif xs[i][j] == "E":
if j < len(xs[i]) - 2:
if xs[i][j + 2] != "W" and xs[i - 1][j + 1] != "S":
if xs[i][j + 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j + 1] ,ys[i][j] = "E" ,"."
continue
else:
if xs[i][j + 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j + 1] ,ys[i][j] = "E" ,"."
continue
elif xs[i][j] == "W":
if xs[i][j - 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j - 1] ,ys[i][j] = "W" ,"."
continue
elif xs[i][j] == "N":
if xs[i - 1][j + 1] != "W" and xs[i - 2][j] != "S" and xs[i - 1][j - 1] != "E":
if xs[i - 1][j] == "X":
ys[i][j] = "."
continue
elif xs[i - 1][j] == ".":
ys[i - 1][j] ,ys[i][j] = "N" ,"."
continue
xs = ys
else:
ans.append("NA")
hinan() |
s254610284 | p00210 | u673933691 | 1404031789 | Python | Python | py | Runtime Error | 0 | 0 | 5532 | import copy
def hinan():
ans = []
while True:
n = raw_input().split(" ")
if n == ["0" ,"0"]:
for an in ans:
print an
break
elif len(n) == 2:
xs = []
k = int(n[1])
for m in range(k):
n = map(str,raw_input())
xs.append(n)
for time in range(181):
check = []
for i in range(len(xs)):
if not any(x in xs[i] for x in ["W","E","N","S"]):
check.append(True)
continue
else:
check.append(False)
for j in range(len(xs[i])):
if xs[i][j] == "S":
if xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j] == "W":
if xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i][j] == "E":
if xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
elif xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i][j] == "N":
if xs[i][j + 1] in ["." ,"X"]:
xs[i][j] = "E"
elif xs[i - 1][j] in ["." ,"X"]:
xs[i][j] = "N"
elif xs[i][j - 1] in ["." ,"X"]:
xs[i][j] = "W"
elif xs[i + 1][j] in ["." ,"X"]:
xs[i][j] = "S"
ys = copy.deepcopy(xs)
if all(check):
ans.append(time)
break
for i in range(len(xs)):
for j in range(len(xs[i])):
if xs[i][j] == "S":
if xs[i + 1][j + 1] != "W":
if xs[i + 1][j] == "X":
ys[i][j] = "."
continue
else:
ys[i + 1][j] ,ys[i][j] = "S" ,"."
continue
elif xs[i][j] == "E":
if j < len(xs[i]) - 2:
if xs[i][j + 2] != "W" and xs[i - 1][j + 1] != "S":
if xs[i][j + 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j + 1] ,ys[i][j] = "E" ,"."
continue
else:
if xs[i][j + 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j + 1] ,ys[i][j] = "E" ,"."
continue
elif xs[i][j] == "W":
if xs[i][j - 1] == "X":
ys[i][j] = "."
continue
else:
ys[i][j - 1] ,ys[i][j] = "W" ,"."
continue
elif xs[i][j] == "N":
if i > 1:
if xs[i - 1][j + 1] != "W" and xs[i - 2][j] != "S" and xs[i - 1][j - 1] != "E":
if xs[i - 1][j] == "X":
ys[i][j] = "."
continue
elif xs[i - 1][j] == ".":
ys[i - 1][j] ,ys[i][j] = "N" ,"."
continue
else:
if xs[i - 1][j + 1] != "W" and xs[i - 1][j - 1] != "E":
if xs[i - 1][j] == "X":
ys[i][j] = "."
continue
elif xs[i - 1][j] == ".":
ys[i - 1][j] ,ys[i][j] = "N" ,"."
continue
xs = ys
else:
ans.append("NA")
hinan() |
s087371571 | p00210 | u673933691 | 1404244109 | Python | Python | py | Runtime Error | 0 | 0 | 2173 | def add(x ,y): return x + y
def hinan():
ans ,houi ,vector = [] ,[[0 ,1] ,[-1 ,0] ,[0 ,-1] ,[1 ,0] ,[0 ,1] ,[-1 , 0] ,[1 ,0]] ,["E" ,"N" ,"W" ,"S"]
while True:
n = raw_input().split(" ")
if n == ["0" ,"0"]:
for an in ans:
print an
break
else:
xs =[[] ,[] ,[]]
for i in range(int(n[1])):
n = raw_input()
for k in range(3):
xs[k] = xs[k] + [[[i ,j] for j in range(len(n)) if n[j] != "#"] ,[[[i ,j] ,houi[vector.index(n[j])]] for j in range(len(n)) if n[j] in vector] ,[[i ,j] for j in range(len(n)) if n[j] == "X"]][k]
for time in range(181):
if len(xs[1]) == 0:
ans.append(time)
break
else:
for i in xs[1]:
for j in range(4):
look_point = map(add ,i[0] ,houi[houi.index(i[1]) - 1 + j])
if look_point in xs[0]:
i[1] = houi[houi.index(i[1]) - 1 + j]
break
go_point ,where = [] ,[i[0] for i in xs[1]]
for i in xs[1]:
go_point.append(map(add ,i[0] ,i[1]))
for i in range(len(go_point)):
if go_point.count(go_point[i]) > 1:
if not go_point[i] in where:
for j in range(4):
if xs[1][i] == [map(add ,go_point[i] ,houi[j]) ,houi[j + 2]]:
xs[1][i][0] ,where[i] = go_point[i] ,go_point[i]
elif [map(add ,go_point[i] ,houi[j]) ,houi[j + 2]] in xs[1]:
break
else:
xs[1][i][0] ,where[i] = go_point[i] ,go_point[i]
if xs[1][i][0] in xs[2]:
del xs[1][i]
print xs ,look_point ,go_point ,where
else:
ans.append("NA")
hinan() |
s762415947 | p00210 | u673933691 | 1404307505 | Python | Python | py | Runtime Error | 0 | 0 | 2038 | def hinan():
ans ,houi ,vector = [] ,[[0 ,1] ,[-1 ,0] ,[0 ,-1] ,[1 ,0] ,[0 ,1] ,[-1 , 0] ,[1 ,0]] ,["E" ,"N" ,"W" ,"S"]
while True:
n = raw_input().split(" ")
if n == ["0" ,"0"]:
for an in ans:
print an
break
else:
xs =[[] ,[] ,[]]
for i in range(int(n[1])):
n = raw_input()
xs = [xs[l] + [[[i ,j] for j in range(len(n)) if n[j] != "#"] ,[[[i ,j] ,houi[vector.index(n[j])]] for j in range(len(n)) if n[j] in vector] ,[[i ,j] for j in range(len(n)) if n[j] == "X"]][l] for l in range(3)]
for time in range(181):
if len(xs[1]) == 0:
ans.append(time)
break
else:
for i in xs[1]:
where ,look_point = [l[0] for l in xs[1]] ,[[k for k in [[i[0][l] + houi[houi.index(i[1]) - 1 + j][l] for l in range(2)] for j in range(4)] if k in xs[0] and not k in where]
if len(look_point) > 0:
i[1] = [look_point[0][s] - i[0][s] for s in range(2)]
go_point = [[i[0][l] + i[1][l] for l in range(2)] for i in xs[1]]
for i in range(len(go_point)):
if go_point.count(go_point[i]) > 1:
if not go_point[i] in where:
for j in range(4):
if xs[1][i] == [[go_point[i][l] + houi[j][l] for l in range(2)] ,houi[j + 2]]:
xs[1][i][0] ,where[i] = go_point[i] ,go_point[i]
elif [[go_point[i][l] + houi[j][l] for l in range(2)] ,houi[j + 2]] in xs[1]:
break
else:
xs[1][i][0] ,where[i] = go_point[i] ,go_point[i]
xs[1] = [i for i in xs[1] if not i[0] in xs[2]]
else:
ans.append("NA")
hinan() |
s202528482 | p00210 | u673933691 | 1404390349 | Python | Python | py | Runtime Error | 0 | 0 | 2030 | def hinan():
ans ,houi ,vector = [] ,[[0 ,1] ,[-1 ,0] ,[0 ,-1] ,[1 ,0] ,[0 ,1] ,[-1 , 0] ,[1 ,0]] ,["E" ,"N" ,"W" ,"S"]
while True:
n = raw_input().split(" ")
if n == ["0" ,"0"]:
for an in ans:
print an
break
else:
xs =[[] ,[] ,[]]
for i in range(int(n[1])):
n = raw_input()
xs = [xs[l] + [[[i ,j] for j in range(len(n)) if n[j] != "#"] ,[[[i ,j] ,houi[vector.index(n[j])]] for j in range(len(n)) if n[j] in vector] ,[[i ,j] for j in range(len(n)) if n[j] == "X"]][l] for l in range(3)]
for time in range(181):
print xs
if len(xs[1]) == 0:
ans.append(time)
break
else:
for i in xs[1]:
where = [l[0] for l in xs[1]]
if len([k for k in [[i[0][l] + houi[houi.index(i[1]) - 1 + j][l] for l in range(2)] for j in range(4)] if k in xs[0] and not k in where]) > 0:
i[1] = [[k for k in [[i[0][l] + houi[houi.index(i[1]) - 1 + j][l] for l in range(2)] for j in range(4)] if k in xs[0] and not k in where][0][s] - i[0][s] for s in range(2)]
go_point = [[i[0][l] + i[1][l] for l in range(2)] for i in xs[1]]
for i in range(len(go_point)):
if go_point.count(go_point[i]) > 1:
if not go_point[i] in where:
for j in range(4):
if xs[1][i] != [[go_point[i][l] + houi[j][l] for l in range(2)] ,houi[j + 2]] and [[go_point[i][l] + houi[j][l] for l in range(2)] ,houi[j + 2]] in xs[1]:
go_point[i] = xs[1][0]
break
xs[1] = [[go_point[i] ,xs[1][i][1]] for i in range(len(xs[1])) if not go_point[i] in xs[2]]
else:
ans.append("NA")
hinan() |
s894867641 | p00210 | u673933691 | 1404390464 | Python | Python | py | Runtime Error | 0 | 0 | 2005 | def hinan():
ans ,houi ,vector = [] ,[[0 ,1] ,[-1 ,0] ,[0 ,-1] ,[1 ,0] ,[0 ,1] ,[-1 , 0] ,[1 ,0]] ,["E" ,"N" ,"W" ,"S"]
while True:
n = raw_input().split(" ")
if n == ["0" ,"0"]:
for an in ans:
print an
break
else:
xs =[[] ,[] ,[]]
for i in range(int(n[1])):
n = raw_input()
xs = [xs[l] + [[[i ,j] for j in range(len(n)) if n[j] != "#"] ,[[[i ,j] ,houi[vector.index(n[j])]] for j in range(len(n)) if n[j] in vector] ,[[i ,j] for j in range(len(n)) if n[j] == "X"]][l] for l in range(3)]
for time in range(181):
if len(xs[1]) == 0:
ans.append(time)
break
else:
for i in xs[1]:
where = [l[0] for l in xs[1]]
if len([k for k in [[i[0][l] + houi[houi.index(i[1]) - 1 + j][l] for l in range(2)] for j in range(4)] if k in xs[0] and not k in where]) > 0:
i[1] = [[k for k in [[i[0][l] + houi[houi.index(i[1]) - 1 + j][l] for l in range(2)] for j in range(4)] if k in xs[0] and not k in where][0][s] - i[0][s] for s in range(2)]
go_point = [[i[0][l] + i[1][l] for l in range(2)] for i in xs[1]]
for i in range(len(go_point)):
if go_point.count(go_point[i]) > 1:
if not go_point[i] in where:
for j in range(4):
if xs[1][i] != [[go_point[i][l] + houi[j][l] for l in range(2)] ,houi[j + 2]] and [[go_point[i][l] + houi[j][l] for l in range(2)] ,houi[j + 2]] in xs[1]:
go_point[i] = xs[1][0]
break
xs[1] = [[go_point[i] ,xs[1][i][1]] for i in range(len(xs[1])) if not go_point[i] in xs[2]]
else:
ans.append("NA")
hinan() |
s747172782 | p00210 | u567380442 | 1429154503 | Python | Python3 | py | Runtime Error | 0 | 0 | 2453 | from sys import stdin
readline = stdin.readline
from itertools import product
N, W, S, E = (0, -1), (-1, 0), (0, 1), (1, 0)
BLANK = ('.', 'X')
DIRECTION = {
'N': N,
'W': W,
'S': S,
'E': E,
}
check_priority = {
N: (E, N, W, S),
W: (N, W, S, E),
S: (W, S, E, N),
E: (S, E, N, W),
}
step_priority = (E, N, W, S)
def search_people(sq):
people = []
for y, x in product(range(h), range(w)):
if sq[y][x] in DIRECTION:
sq[y][x] = person = Person(x, y, DIRECTION[sq[y][x]], sq)
people.append(person)
return people
class Person:
def __init__(self, x, y, direction, sq):
self.x, self.y = x, y
self.direction = direction
self.sq = sq
self.evacuating = True
def check_direction(self):
for direction in check_priority[self.direction]:
dx, dy = direction
if self.sq[self.y + dy][self.x + dx] in BLANK:
self.direction = direction
break
def check_stepable(self):
dx, dy = self.direction
x, y = self.x + dx, self.y + dy
if self.sq[y][x] == 'X':
return True
for dx, dy in step_priority:
tmp = self.sq[y + dy][x + dx]
if not isinstance(tmp, Person):
continue
if tmp == self:
self.stepable = True
break
dx, dy = tmp.direction
if tmp.x + dx == x and tmp.y + dy == y:
self.stepable = False
break
def __repr__(self):
return "'P'"
def step(self):
if self.stepable:
dx, dy = self.direction
self.sq[self.y][self.x] = '.'
self.x += dx
self.y += dy
if self.sq[self.y][self.x] == '.':
self.sq[self.y][self.x] = self
else:
self.evacuating = False
while True:
w, h = map(int, readline().split())
if w == 0:
break
squares = [list(readline().strip()) for _ in range(h)]
people = search_people(squares)
for i in range(180):
for pi in people:
pi.check_direction()
for pi in people:
pi.check_stepable()
for pi in people:
pi.step()
people = [pi for pi in people if pi.evacuating]
if len(people) == 0:
print(i + 1)
break
else:
print('NA') |
s666059391 | p00210 | u567380442 | 1429154746 | Python | Python3 | py | Runtime Error | 0 | 0 | 2480 | from sys import stdin
readline = stdin.readline
from itertools import product
N, W, S, E = (0, -1), (-1, 0), (0, 1), (1, 0)
BLANK = ('.', 'X')
DIRECTION = {
'N': N,
'W': W,
'S': S,
'E': E,
}
check_priority = {
N: (E, N, W, S),
W: (N, W, S, E),
S: (W, S, E, N),
E: (S, E, N, W),
}
step_priority = (E, N, W, S)
def search_people(sq):
people = []
for y, x in product(range(h), range(w)):
if sq[y][x] in DIRECTION:
sq[y][x] = person = Person(x, y, DIRECTION[sq[y][x]], sq)
people.append(person)
return people
class Person:
def __init__(self, x, y, direction, sq):
self.x, self.y = x, y
self.direction = direction
self.sq = sq
self.evacuating = True
def check_direction(self):
for direction in check_priority[self.direction]:
dx, dy = direction
if self.sq[self.y + dy][self.x + dx] in BLANK:
self.direction = direction
break
def check_stepable(self):
dx, dy = self.direction
x, y = self.x + dx, self.y + dy
if self.sq[y][x] == 'X':
self.stepable = True
return
for dx, dy in step_priority:
tmp = self.sq[y + dy][x + dx]
if not isinstance(tmp, Person):
continue
if tmp == self:
self.stepable = True
break
dx, dy = tmp.direction
if tmp.x + dx == x and tmp.y + dy == y:
self.stepable = False
break
def __repr__(self):
return "'P'"
def step(self):
if self.stepable:
dx, dy = self.direction
self.sq[self.y][self.x] = '.'
self.x += dx
self.y += dy
if self.sq[self.y][self.x] == '.':
self.sq[self.y][self.x] = self
else:
self.evacuating = False
while True:
w, h = map(int, readline().split())
if w == 0:
break
squares = [list(readline().strip()) for _ in range(h)]
people = search_people(squares)
for i in range(180):
for pi in people:
pi.check_direction()
for pi in people:
pi.check_stepable()
for pi in people:
pi.step()
people = [pi for pi in people if pi.evacuating]
if len(people) == 0:
print(i + 1)
break
else:
print('NA') |
s986576441 | p00211 | u873482706 | 1437133552 | Python | Python | py | Runtime Error | 0 | 0 | 926 | import copy
def main():
_data = copy.deepcopy(data)
while 1 < len(_data):
d1, v1 = _data[0]
d2, v2 = _data[1]
l = f1(v1, v2)
v = l
m1, m2 = list(f2(l, v1, v2))
d = f1(d1*m1, d2*m2)
for i in range(2): del _data[0]
_data.append([d, v])
else:
f3(_data[0])
def f1(a, b):
x, y = (a, b) if a >= b else (b, a)
g = gcd(x, y)
return lcm(x, y, g)
def f2(l, *s):
for v in s:
yield l/v
def f3(_data):
d1, v1 = _data
for d2, v2 in data:
ans = str((float(d1)/v1)/(float(d2)/v2))
print int(ans[:-2])
def gcd(x, y):
while y != 0:
x = x-(x/y)*y
x, y = y, x
else:
return x
def lcm(x, y, g):
return (x*y)/g
while True:
n = int(raw_input())
if n == 0: break
data = [map(int, line.rstrip().split()) for line in open('s.txt')]
main() |
s163643900 | p00211 | u755162050 | 1475596406 | Python | Python3 | py | Runtime Error | 0 | 0 | 992 | def gcd(x, y):
while y:
x, y = y, x % y
return x
def lcm(x, y):
l_lcm = (x * y) // gcd(x, y)
return l_lcm
def mul_lcm(array):
l = lcm(array[0], array[1])
if len(array) > 3:
for i in range(2, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students):
denominator_lcm = mul_lcm([y for _, y in students])
for i in range(len(students)):
students[i][0] *= int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm([x for x, _ in students])
return [int(molecular_lcm / students[i][0]) for i in range(len(students))]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = []
for _ in range(n):
students.append(list(map(int, input().split())))
answer_list = algorithm(students)
for ans in answer_list:
print(ans)
def main():
input_sample()
if __name__ == '__main__':
main() |
s001230172 | p00211 | u755162050 | 1475596738 | Python | Python3 | py | Runtime Error | 0 | 0 | 1185 | """ Created by Jieyi on 10/4/16. """
import io
import sys
if len(sys.argv) > 1:
filename = sys.argv[1]
inp = ''.join(open(filename, "r").readlines())
sys.stdin = io.StringIO(inp)
def gcd(x, y):
while y:
x, y = y, x % y
return x
def lcm(x, y):
l_lcm = (x * y) // gcd(x, y)
return l_lcm
def mul_lcm(array):
l = lcm(array[0], array[1])
if len(array) > 3:
for i in range(2, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students):
denominator_lcm = mul_lcm([y for _, y in students])
for i in range(len(students)):
students[i][0] *= int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm([x for x, _ in students])
return [int(molecular_lcm / students[i][0]) for i in range(len(students))]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = []
for _ in range(n):
students.append(list(map(int, input().split())))
answer_list = algorithm(students)
for ans in answer_list:
print(ans)
def main():
input_sample()
if __name__ == '__main__':
main() |
s285909499 | p00211 | u755162050 | 1476538609 | Python | Python3 | py | Runtime Error | 0 | 0 | 890 | def lcm(x, y):
return (x * y) / gcd(x, y)
def mul_lcm(array):
l = array[0]
if len(array) > 1:
for i in range(1, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students):
denominator_lcm = mul_lcm([y for _, y in students])
for i in range(len(students)):
students[i][0] *= int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm([x for x, _ in students])
return [int(molecular_lcm / students[i][0]) for i in range(len(students))]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = []
for _ in range(n):
students.append(list(map(int, input().split())))
answer_list = algorithm(students)
for ans in answer_list:
print(ans)
def main():
input_sample()
if __name__ == '__main__':
main() |
s218161754 | p00211 | u755162050 | 1476539075 | Python | Python3 | py | Runtime Error | 0 | 0 | 1166 | """ Created by Jieyi on 10/4/16. """
import io
import sys
from fractions import gcd
if len(sys.argv) > 1:
filename = sys.argv[1]
inp = ''.join(open(filename, "r").readlines())
sys.stdin = io.StringIO(inp)
def lcm(x, y):
return (x * y) / gcd(x, y)
def mul_lcm(array):
l = array[0]
if len(array) > 1:
for i in range(1, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students, n):
denominator_lcm = mul_lcm([y for _, y in students])
for i in range(len(students)):
students[i][0] *= int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm([x for x, _ in students])
return [int(molecular_lcm / students[i][0]) for i in range(len(students))]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = [[-1, -1] for _ in range(10)]
for i in range(n):
students[i][0], students[i][1] = list(map(int, input().split()))
answer_list = algorithm(students, n)
for i in range(n):
print(answer_list[i])
def main():
input_sample()
if __name__ == '__main__':
main() |
s193297547 | p00211 | u755162050 | 1476573933 | Python | Python3 | py | Runtime Error | 0 | 0 | 1166 | """ Created by Jieyi on 10/4/16. """
import io
import sys
from fractions import gcd
if len(sys.argv) > 1:
filename = sys.argv[1]
inp = ''.join(open(filename, "r").readlines())
sys.stdin = io.StringIO(inp)
def lcm(x, y):
return (x * y) / gcd(x, y)
def mul_lcm(array):
l = array[0]
if len(array) > 1:
for i in range(1, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students, n):
denominator_lcm = mul_lcm([y for _, y in students])
for i in range(len(students)):
students[i][0] *= int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm([x for x, _ in students])
return [int(molecular_lcm / students[i][0]) for i in range(len(students))]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = [[-1, -1] for _ in range(20)]
for i in range(n):
students[i][0], students[i][1] = list(map(int, input().split()))
answer_list = algorithm(students, n)
for i in range(n):
print(answer_list[i])
def main():
input_sample()
if __name__ == '__main__':
main() |
s860012703 | p00211 | u755162050 | 1476573989 | Python | Python3 | py | Runtime Error | 0 | 0 | 973 | from fractions import gcd
def lcm(x, y):
return (x * y) / gcd(x, y)
def mul_lcm(array):
l = array[0]
if len(array) > 1:
for i in range(1, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students, n):
denominator_lcm = mul_lcm([y for _, y in students])
for i in range(len(students)):
students[i][0] *= int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm([x for x, _ in students])
return [int(molecular_lcm / students[i][0]) for i in range(len(students))]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = [[-1, -1] for _ in range(20)]
for i in range(n):
students[i][0], students[i][1] = list(map(int, input().split()))
answer_list = algorithm(students, n)
for i in range(n):
print(answer_list[i])
def main():
input_sample()
if __name__ == '__main__':
main() |
s349390968 | p00211 | u755162050 | 1476574085 | Python | Python3 | py | Runtime Error | 0 | 0 | 1104 | import math
if len(sys.argv) > 1:
filename = sys.argv[1]
inp = ''.join(open(filename, "r").readlines())
sys.stdin = io.StringIO(inp)
def lcm(x, y):
return int((x * y) / math.gcd(x, y))
def mul_lcm(array):
l = array[0]
if len(array) > 1:
for i in range(1, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students, n):
denominator_lcm = mul_lcm([y for _, y in students])
for i in range(len(students)):
students[i][0] *= int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm([x for x, _ in students])
return [int(molecular_lcm / students[i][0]) for i in range(len(students))]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = [[-1, -1] for _ in range(20)]
for i in range(n):
students[i][0], students[i][1] = list(map(int, input().split()))
answer_list = algorithm(students, n)
for i in range(n):
print(answer_list[i])
def main():
input_sample()
if __name__ == '__main__':
main() |
s858854226 | p00211 | u755162050 | 1476574123 | Python | Python3 | py | Runtime Error | 0 | 0 | 969 | import math
def lcm(x, y):
return int((x * y) / math.gcd(x, y))
def mul_lcm(array):
l = array[0]
if len(array) > 1:
for i in range(1, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students, n):
denominator_lcm = mul_lcm([y for _, y in students])
for i in range(len(students)):
students[i][0] *= int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm([x for x, _ in students])
return [int(molecular_lcm / students[i][0]) for i in range(len(students))]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = [[-1, -1] for _ in range(20)]
for i in range(n):
students[i][0], students[i][1] = list(map(int, input().split()))
answer_list = algorithm(students, n)
for i in range(n):
print(answer_list[i])
def main():
input_sample()
if __name__ == '__main__':
main() |
s040075929 | p00211 | u755162050 | 1476575309 | Python | Python3 | py | Runtime Error | 0 | 0 | 974 | import math
def lcm(x, y):
return int((x * y) / math.gcd(x, y))
def mul_lcm(array):
l = array[0]
if len(array) > 1:
for i in range(1, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students, n):
den = [students[i][1] for i in range(n)]
denominator_lcm = mul_lcm(den)
ans = [-1] * 20
for i in range(n):
ans[i] = students[i][0] * int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm(ans[0:n])
return [int(molecular_lcm / ans[i]) for i in range(n)]
def input_sample():
while True:
n = int(input())
if n == 0:
break
students = [[-1, -1] for _ in range(20)]
for i in range(n):
students[i][0], students[i][1] = list(map(int, input().split()))
answer_list = algorithm(students, n)
for i in range(n):
print(answer_list[i])
def main():
input_sample()
if __name__ == '__main__':
main() |
s873117096 | p00211 | u755162050 | 1476575540 | Python | Python3 | py | Runtime Error | 0 | 0 | 1247 | """ Created by Jieyi on 10/4/16. """
import io
import sys
import math
if len(sys.argv) > 1:
filename = sys.argv[1]
inp = ''.join(open(filename, "r").readlines())
sys.stdin = io.StringIO(inp)
def lcm(x, y):
return int((x * y) / math.gcd(x, y))
def mul_lcm(array):
l = array[0]
if len(array) > 1:
for i in range(1, len(array)):
l = lcm(array[i], l)
return l
def algorithm(students, n):
den = [students[i][1] for i in range(n)]
denominator_lcm = mul_lcm(den)
ans = [-1] * 20
for i in range(n):
ans[i] = students[i][0] * int(denominator_lcm / students[i][1])
molecular_lcm = mul_lcm(ans[0:n])
return [int(molecular_lcm / ans[i]) for i in range(n)]
def input_sample():
while True:
n = int(input())
if n == 0:
break
# students = [[-1, -1] for _ in range(20)]
# for i in range(n):
# students[i][0], students[i][1] = list(map(int, input().split()))
students = [list(map(int, input().split(' '))) for _ in range(n)]
answer_list = algorithm(students, n)
for i in range(n):
print(answer_list[i])
def main():
input_sample()
if __name__ == '__main__':
main() |
s031195889 | p00212 | u874172052 | 1435216996 | Python | Python | py | Runtime Error | 0 | 0 | 1409 | def express_bus(coupon,city,route,start,end):
fare = {}
adjacent = []
for i in range(route):
s,t,cost = map(int,raw_input().split())
fare[s,t] = cost
fare[t,s] = cost
for i in range(1,city+1):
adjacent.append([])
for j in fare:
if i == j[0]:
adjacent[i-1].append(j[1])
route = search(end,[start],adjacent)
minimum_fare = []
for path in route:
each_path = [([path[i-1],path[i]]) for i in range(1,len(path))]
costs = [fare[s,t] for s,t in each_path]
total_fare = sum(costs)
with_coupon = []
for i in range(coupon):
half_fare = max(costs)/2
with_coupon.append(half_fare)
costs.remove(max(costs))
if costs == []:
break
minimum_fare.append(sum(costs+with_coupon))
return min(minimum_fare)
def search(goal,path,adjacent,route=[]):
n = path[len(path)-1]
if n == goal:
r = path[:]
route.append(r)
else:
for i in adjacent[n-1]:
if i not in path:
path.append(i)
search(goal,path,adjacent)
path.pop()
return route
while True:
coupon,city,route,start,end = map(int,raw_input().split(" "))
if city == 0 and route == 0 and coupon == 0:
break
print express_bus(coupon,city,route,start,end) |
s184500826 | p00212 | u685815919 | 1473841700 | Python | Python | py | Runtime Error | 0 | 0 | 1403 | import sys
def dijkstra(nodes, start, matrix):
defnode = [False] * (nodes)
cost = [sys.maxint] * (nodes)
cost[start] = 0
node = start
counter = 0
while True:
counter += 1
if counter == nodes:
return cost
defnode[node] = True
for i in xrange(1, nodes):
if defnode[i]:
continue
if matrix[node][i] == sys.maxint:
continue
cost[i] = min(cost[i], cost[node]+matrix[node][i])
minnode = sys.maxint
mincost = sys.maxint
for i in xrange(1, nodes):
if defnode[i]:
continue
if cost[i] < mincost:
minnode = i
mincost = cost[i]
node = minnode
def get_state(a, c, k):
return (a-1) * (c+1) + k
while True:
c,n,m,s,d = map(int, raw_input().split())
if c == 0:
break
matrix = [[sys.maxint] * n*(c+1) for i in xrange(n*(c+1))]
for i in xrange(m):
a,b,f = map(int, raw_input().split())
# no use ticket
for i in xrange(c+1):
matrix[get_state(a, c, i)][get_state(b, c, i)] = f
matrix[get_state(b, c, i)][get_state(a, c, i)] = f
# use ticket
for i in xrange(c):
matrix[get_state(a, c, i)][get_state(b, c, i+1)] = f/2
matrix[get_state(b, c, i)][get_state(a, c, i+1)] = f/2
costs = dijkstra(n*(c+1), get_state(s, c, 0), matrix)
mincost = sys.maxint
for i in xrange(c+1):
mincost = min(mincost, costs[get_state(d, c, i)])
print mincost |
s322100692 | p00212 | u672443148 | 1516968867 | Python | Python3 | py | Runtime Error | 0 | 0 | 1074 | from heapq import *
while True:
#input c,n,m,s,d & creating G
#G[to,cost]
c,n,m,s,d=map(int,input().split())
if c==n==m==s==d==0:
break
G=[[]]
for i in range(n):
G.append([])
for i in range(m):
a,b,f=map(int,input().split())
G[a].append([b,f])
G[b].append([a,f])
#creating dp[]
INF=1e8
dp=[]
for i in range(c+1):
temp=[INF for j in range(n+1)]
dp.append(temp)
def dijkstra(s,c):
que=[]
dp[0][s]=0
heappush(que,[dp[c][s],s])
while len(que)!=0:
p=heappop(que)
v=p[1] #v is the current location
if(dp[c][v]<p[0]):
continue
for i in range(len(G[v])):
e=G[v][i]
Min=dp[c][v]+e[1] if c==0 else min(dp[c-1][v]+e[1]/2,dp[c][v]+e[1])
if(dp[c][e[0]]>Min):
dp[c][e[0]]=Min
heappush(que,[dp[c][e[0]],e[0]])
for i in range(c+1):
dijkstra(s,i)
print(int(dp[c][d]))
|
s741676712 | p00213 | u567380442 | 1429189625 | Python | Python3 | py | Runtime Error | 0 | 0 | 1871 | from sys import stdin
readline = stdin.readline
from copy import deepcopy
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
Memo = namedtuple('Memo', 'buyer lot x y')
from itertools import product
def placeable(lots, buyer, x, y, w, h):
if x < 0 or len(lots[0]) < x + w or y < 0 or len(lots) < y + h:
return False
for i, j in product(range(y, y + h), range(x, x + w)):
if lots[i][j] not in (0, buyer):
return False
return True
def place(lots, buyer, x, y, w, h):
tmp = deepcopy(lots)
for i, j in product(range(y, y + h), range(x, x + w)):
tmp[i][j] = buyer
return tmp
def solve(lots, memos):
if len(memos) == 0:
global ans, count
ans = lots
count += 1
return
m = memos[0]
for w in range(1, m.lot + 1):
if m.lot % w:
continue
h = m.lot // w
for y, x in product(range(m.y - h + 1, m.y + 1), range(m.x - w + 1, m.x + 1)):
if not placeable(lots, m.buyer, x, y, w, h):
continue
solve(place(lots, m.buyer, x, y, w, h), memos[1:])
def search_sign(lots, w, h):
sign = {}
for y, x in product(range(h), range(w)):
if lots[y][x]:
sign[lots[y][x]] = Point(x, y)
return sign
def main():
while True:
w, h, n = map(int, readline().split())
if w == 0:
break
memos = [map(int, readline().split()) for _ in range(n)]
lots = [list(map(int, readline().split())) for _ in range(h)]
sign = search_sign(lots, w, h)
memos = [Memo(b, l, sign[b].x, sign[b].y) for b, l in memos]
global ans, count
ans, count = None, 0
solve(lots, memos)
if count == 1:
for ai in ans:
print(*ai)
else:
print('NA')
main() |
s559337702 | p00214 | u319725914 | 1535467594 | Python | Python3 | py | Runtime Error | 0 | 0 | 1447 | from sys import stdin
from itertools import product
def chk_in_rect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: return False
else:
return True
def chk_intersect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b < 0 : return True
else:
return False
while(True):
n = int(stdin.readline())
if not n: break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(int, stdin.readline().split())) for __ in range(m) ]
for i in range(m):
for j in range(i+1,m):
if chk_in_rect(xys[i],xys[j]):
# print("in_rect")
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
# print("intersect")
p = [i if e==j else e for e in p]
continue
print(len(set(p)))
|
s768443463 | p00214 | u319725914 | 1535467670 | Python | Python3 | py | Runtime Error | 0 | 0 | 1491 | from sys import stdin
from itertools import product
def chk_in_rect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: return False
else:
return True
def chk_intersect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b < 0 : return True
else:
return False
while(True):
try:
n = int(stdin.readline())
if not n: break
except:
break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(int, stdin.readline().split())) for __ in range(m) ]
for i in range(m):
for j in range(i+1,m):
if chk_in_rect(xys[i],xys[j]):
# print("in_rect")
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
# print("intersect")
p = [i if e==j else e for e in p]
continue
print(len(set(p)))
|
s497681735 | p00214 | u319725914 | 1535506184 | Python | Python3 | py | Runtime Error | 0 | 0 | 1564 | from sys import stdin
from itertools import product
def chk_in_rect(xy1,xy2):
for i in range(4):
chk = True
for j in range(4):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: chk = False; break
if chk: return True
else:
return False
def chk_intersect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b < 0 : return True
else:
return False
while(True):
try:
n = int(stdin.readline())
if not n: break
except:
break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(int, stdin.readline().split())) for __ in range(m) ]
for i in range(m):
for j in range(i+1,m):
if chk_in_rect(xys[i],xys[j]):
# print("in_rect")
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
# print("intersect")
p = [i if e==j else e for e in p]
continue
print(len(set(p)))
|
s739026374 | p00214 | u319725914 | 1535506356 | Python | Python3 | py | Runtime Error | 0 | 0 | 1563 | from sys import stdin
from itertools import product
def chk_in_rect(xy1,xy2):
for i in range(4):
chk = True
for j in range(4):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: chk = False; break
if chk: return True
else:
return False
def chk_intersect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b < 0 : return True
else:
return False
while(True):
try:
n = int(stdin.readline())
if not n: break
except:
break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(int, stdin.readline().split())) for i in range(m) ]
for i in range(m):
for j in range(i+1,m):
if chk_in_rect(xys[i],xys[j]):
# print("in_rect")
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
# print("intersect")
p = [i if e==j else e for e in p]
continue
print(len(set(p)))
|
s386195314 | p00214 | u319725914 | 1535507903 | Python | Python3 | py | Runtime Error | 0 | 0 | 1600 | from sys import stdin
from itertools import product
def chk_in_rect(xy1,xy2):
for i in range(4):
chk = True
for j in range(4):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: chk = False; break
if chk: return True
else:
return False
def chk_intersect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b < 0 : return True
else:
return False
while(True):
try:
n = int(stdin.readline())
if not n: break
except:
break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(int, stdin.readline().split())) for i in range(m) ]
for i in range(m):
if len(set(p)) == 1: print(1); break
for j in range(i+1,m):
if p[i] == p[j]:
continue
if chk_in_rect(xys[i],xys[j]):
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
p = [i if e==j else e for e in p]
continue
else: print(len(set(p)))
|
s278349724 | p00214 | u319725914 | 1535508304 | Python | Python3 | py | Runtime Error | 0 | 0 | 1602 | from sys import stdin
from itertools import product
def chk_in_rect(xy1,xy2):
for i in range(4):
chk = True
for j in range(4):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: chk = False; break
if chk: return True
else:
return False
def chk_intersect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b < 0 : return True
else:
return False
while(True):
try:
n = int(stdin.readline())
if not n: break
except:
break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(float, stdin.readline().split())) for i in range(m) ]
for i in range(m):
if len(set(p)) == 1: print(1); break
for j in range(i+1,m):
if p[i] == p[j]:
continue
if chk_in_rect(xys[i],xys[j]):
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
p = [i if e==j else e for e in p]
continue
else: print(len(set(p)))
|
s046042068 | p00214 | u319725914 | 1535517046 | Python | Python3 | py | Runtime Error | 0 | 0 | 1689 | from sys import stdin
from itertools import product
def chk_in_rect(xy1,xy2):
chk = True
for i in range(4):
for j in range(4):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: chk = False; break
if chk: return True
else: return False
def chk_intersect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b < 0 : return True
else:
return False
while(True):
try:
n = int(stdin.readline())
if not n: break
except:
break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(int, stdin.readline().split())) for i in range(m) ]
# print(n,m,xys)
for i in range(m):
if len(set(p)) == 1: print(1); break
for j in range(i+1,m):
if p[i] == p[j]:
continue
if chk_in_rect(xys[i],xys[j]):
# print("in_rect")
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
# print("intersect")
p = [i if e==j else e for e in p]
continue
else: print(len(set(p)))
|
s068660280 | p00214 | u319725914 | 1535525918 | Python | Python3 | py | Runtime Error | 0 | 0 | 2024 | from sys import stdin
from itertools import product
def chk_in_rect(xy1,xy2):
chk2in1 = True
for i in range(4):
for j in range(4):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: chk2in1 = False; break
chk1in2 = True
for i in range(4):
for j in range(4):
a = (xy2[(2*i+2)&7]-xy2[(2*i )&7]) * (xy1[(2*j+1)&7]-xy2[(2*i+1)&7])
b = (xy2[(2*i+3)&7]-xy2[(2*i+1)&7]) * (xy1[(2*j )&7]-xy2[(2*i )&7])
if a > b: chk2in1 = False; break
if chk2in1|chk1in2: return True
else: return False
def chk_intersect(xy1,xy2):
for i,j in product(range(4),repeat=2):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b <= 0 : return True
else:
return False
while(True):
try:
n = int(stdin.readline())
if not n: break
except:
break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(int, stdin.readline().split())) for i in range(m) ]
print(1)
continue
# print(n,m,xys)
for i in range(m):
if len(set(p)) == 1: print(1); break
for j in range(i+1,m):
if p[i] == p[j]:
continue
if chk_in_rect(xys[i],xys[j]):
# print("in_rect")
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
# print("intersect")
p = [i if e==j else e for e in p]
continue
else: print(p,len(set(p)))
|
s674044506 | p00214 | u319725914 | 1535525984 | Python | Python3 | py | Runtime Error | 0 | 0 | 2021 | from sys import stdin
def chk_in_rect(xy1,xy2):
chk2in1 = True
for i in range(4):
for j in range(4):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: chk2in1 = False; break
chk1in2 = True
for i in range(4):
for j in range(4):
a = (xy2[(2*i+2)&7]-xy2[(2*i )&7]) * (xy1[(2*j+1)&7]-xy2[(2*i+1)&7])
b = (xy2[(2*i+3)&7]-xy2[(2*i+1)&7]) * (xy1[(2*j )&7]-xy2[(2*i )&7])
if a > b: chk2in1 = False; break
if chk2in1|chk1in2: return True
else: return False
def chk_intersect(xy1,xy2):
for i in range(4):
for j in range(4):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b <= 0 : return True
else:
return False
while(True):
try:
n = int(stdin.readline())
if not n: break
except:
break
for _ in range(n):
m = int(stdin.readline())
p = list(range(m))
xys = [ list(map(int, stdin.readline().split())) for i in range(m) ]
print(1)
continue
# print(n,m,xys)
for i in range(m):
if len(set(p)) == 1: print(1); break
for j in range(i+1,m):
if p[i] == p[j]:
continue
if chk_in_rect(xys[i],xys[j]):
# print("in_rect")
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
# print("intersect")
p = [i if e==j else e for e in p]
continue
else: print(p,len(set(p)))
|
s942080519 | p00214 | u319725914 | 1535526027 | Python | Python3 | py | Runtime Error | 0 | 0 | 1972 |
def chk_in_rect(xy1,xy2):
chk2in1 = True
for i in range(4):
for j in range(4):
a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
if a > b: chk2in1 = False; break
chk1in2 = True
for i in range(4):
for j in range(4):
a = (xy2[(2*i+2)&7]-xy2[(2*i )&7]) * (xy1[(2*j+1)&7]-xy2[(2*i+1)&7])
b = (xy2[(2*i+3)&7]-xy2[(2*i+1)&7]) * (xy1[(2*j )&7]-xy2[(2*i )&7])
if a > b: chk2in1 = False; break
if chk2in1|chk1in2: return True
else: return False
def chk_intersect(xy1,xy2):
for i in range(4):
for j in range(4):
a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
if a*b <= 0 : return True
else:
return False
while(True):
try:
n = int(input())
if not n: break
except:
break
for _ in range(n):
m = int(input())
p = list(range(m))
xys = [ list(map(int, input().split())) for i in range(m) ]
print(1)
continue
# print(n,m,xys)
for i in range(m):
if len(set(p)) == 1: print(1); break
for j in range(i+1,m):
if p[i] == p[j]:
continue
if chk_in_rect(xys[i],xys[j]):
# print("in_rect")
p = [i if e==j else e for e in p]
continue
if chk_intersect(xys[i],xys[j]):
# print("intersect")
p = [i if e==j else e for e in p]
continue
else: print(p,len(set(p)))
|
s518550928 | p00214 | u319725914 | 1535526064 | Python | Python3 | py | Runtime Error | 0 | 0 | 2052 |
# def chk_in_rect(xy1,xy2):
# chk2in1 = True
# for i in range(4):
# for j in range(4):
# a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
# b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
# if a > b: chk2in1 = False; break
# chk1in2 = True
# for i in range(4):
# for j in range(4):
# a = (xy2[(2*i+2)&7]-xy2[(2*i )&7]) * (xy1[(2*j+1)&7]-xy2[(2*i+1)&7])
# b = (xy2[(2*i+3)&7]-xy2[(2*i+1)&7]) * (xy1[(2*j )&7]-xy2[(2*i )&7])
# if a > b: chk2in1 = False; break
# if chk2in1|chk1in2: return True
# else: return False
# def chk_intersect(xy1,xy2):
# for i in range(4):
# for j in range(4):
# a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
# a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
# b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
# b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
# if a*b <= 0 : return True
# else:
# return False
while(True):
try:
n = int(input())
if not n: break
except:
break
for _ in range(n):
m = int(input())
p = list(range(m))
xys = [ list(map(int, input().split())) for i in range(m) ]
print(1)
continue
# # print(n,m,xys)
# for i in range(m):
# if len(set(p)) == 1: print(1); break
# for j in range(i+1,m):
# if p[i] == p[j]:
# continue
# if chk_in_rect(xys[i],xys[j]):
# # print("in_rect")
# p = [i if e==j else e for e in p]
# continue
# if chk_intersect(xys[i],xys[j]):
# # print("intersect")
# p = [i if e==j else e for e in p]
# continue
# else: print(p,len(set(p)))
|
s237613453 | p00214 | u319725914 | 1535526113 | Python | Python3 | py | Runtime Error | 0 | 0 | 2009 |
# def chk_in_rect(xy1,xy2):
# chk2in1 = True
# for i in range(4):
# for j in range(4):
# a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
# b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
# if a > b: chk2in1 = False; break
# chk1in2 = True
# for i in range(4):
# for j in range(4):
# a = (xy2[(2*i+2)&7]-xy2[(2*i )&7]) * (xy1[(2*j+1)&7]-xy2[(2*i+1)&7])
# b = (xy2[(2*i+3)&7]-xy2[(2*i+1)&7]) * (xy1[(2*j )&7]-xy2[(2*i )&7])
# if a > b: chk2in1 = False; break
# if chk2in1|chk1in2: return True
# else: return False
# def chk_intersect(xy1,xy2):
# for i in range(4):
# for j in range(4):
# a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
# a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
# b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
# b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
# if a*b <= 0 : return True
# else:
# return False
while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
p = list(range(m))
xys = [ list(map(int, input().split())) for i in range(m) ]
print(1)
continue
# # print(n,m,xys)
# for i in range(m):
# if len(set(p)) == 1: print(1); break
# for j in range(i+1,m):
# if p[i] == p[j]:
# continue
# if chk_in_rect(xys[i],xys[j]):
# # print("in_rect")
# p = [i if e==j else e for e in p]
# continue
# if chk_intersect(xys[i],xys[j]):
# # print("intersect")
# p = [i if e==j else e for e in p]
# continue
# else: print(p,len(set(p)))
|
s616130422 | p00214 | u319725914 | 1535526155 | Python | Python3 | py | Runtime Error | 0 | 0 | 2011 |
# def chk_in_rect(xy1,xy2):
# chk2in1 = True
# for i in range(4):
# for j in range(4):
# a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
# b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
# if a > b: chk2in1 = False; break
# chk1in2 = True
# for i in range(4):
# for j in range(4):
# a = (xy2[(2*i+2)&7]-xy2[(2*i )&7]) * (xy1[(2*j+1)&7]-xy2[(2*i+1)&7])
# b = (xy2[(2*i+3)&7]-xy2[(2*i+1)&7]) * (xy1[(2*j )&7]-xy2[(2*i )&7])
# if a > b: chk2in1 = False; break
# if chk2in1|chk1in2: return True
# else: return False
# def chk_intersect(xy1,xy2):
# for i in range(4):
# for j in range(4):
# a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
# a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
# b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
# b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
# if a*b <= 0 : return True
# else:
# return False
while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
# p = list(range(m))
xys = [ list(map(int, input().split())) for i in range(m) ]
print(1)
continue
# # print(n,m,xys)
# for i in range(m):
# if len(set(p)) == 1: print(1); break
# for j in range(i+1,m):
# if p[i] == p[j]:
# continue
# if chk_in_rect(xys[i],xys[j]):
# # print("in_rect")
# p = [i if e==j else e for e in p]
# continue
# if chk_intersect(xys[i],xys[j]):
# # print("intersect")
# p = [i if e==j else e for e in p]
# continue
# else: print(p,len(set(p)))
|
s373926588 | p00214 | u319725914 | 1535526188 | Python | Python3 | py | Runtime Error | 0 | 0 | 233 | while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
# p = list(range(m))
xys = [ list(map(int, input().split())) for i in range(m) ]
print(1)
continue
|
s078351720 | p00214 | u319725914 | 1535526456 | Python | Python3 | py | Runtime Error | 0 | 0 | 227 | while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
# p = list(range(m))
xys = [ map(int, input().split()) for i in range(m) ]
print(1)
continue
|
s749093849 | p00214 | u319725914 | 1535526480 | Python | Python3 | py | Runtime Error | 0 | 0 | 209 | while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
# p = list(range(m))
xys = [ input() for i in range(m) ]
print(1)
continue
|
s985937755 | p00214 | u319725914 | 1535532620 | Python | Python3 | py | Runtime Error | 0 | 0 | 1983 |
# def chk_in_rect(xy1,xy2):
# chk2in1 = True
# for i in range(4):
# for j in range(4):
# a = (xy1[(2*i+2)&7]-xy1[(2*i )&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+1)&7])
# b = (xy1[(2*i+3)&7]-xy1[(2*i+1)&7]) * (xy2[(2*j )&7]-xy1[(2*i )&7])
# if a > b: chk2in1 = False; break
# chk1in2 = True
# for i in range(4):
# for j in range(4):
# a = (xy2[(2*i+2)&7]-xy2[(2*i )&7]) * (xy1[(2*j+1)&7]-xy2[(2*i+1)&7])
# b = (xy2[(2*i+3)&7]-xy2[(2*i+1)&7]) * (xy1[(2*j )&7]-xy2[(2*i )&7])
# if a > b: chk2in1 = False; break
# if chk2in1|chk1in2: return True
# else: return False
# def chk_intersect(xy1,xy2):
# for i in range(4):
# for j in range(4):
# a = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+1)&7]-xy1[(2*i+3)&7])
# a+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j )&7])
# b = (xy1[(2*i )&7]-xy1[(2*i+2)&7]) * (xy2[(2*j+3)&7]-xy1[(2*i+3)&7])
# b+= (xy1[(2*i+1)&7]-xy1[(2*i+3)&7]) * (xy2[(2*i )&7]-xy1[(2*j+2)&7])
# if a*b <= 0 : return True
# else:
# return False
while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
# p = list(range(m))
xys = [ input() for i in range(m) ]
print(1)
continue
# # print(n,m,xys)
# for i in range(m):
# if len(set(p)) == 1: print(1); break
# for j in range(i+1,m):
# if p[i] == p[j]:
# continue
# if chk_in_rect(xys[i],xys[j]):
# # print("in_rect")
# p = [i if e==j else e for e in p]
# continue
# if chk_intersect(xys[i],xys[j]):
# # print("intersect")
# p = [i if e==j else e for e in p]
# continue
# else: print(p,len(set(p)))
|
s279180811 | p00214 | u319725914 | 1535532843 | Python | Python3 | py | Runtime Error | 0 | 0 | 226 | while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
# p = list(range(m))
xys = [ map(int,input().split()) for i in range(m) ]
print(1)
continue
|
s842903732 | p00214 | u319725914 | 1535533423 | Python | Python3 | py | Runtime Error | 0 | 0 | 180 | while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
xys = [ map(int,input().split()) for i in range(m) ]
print(1)
|
s346735987 | p00214 | u319725914 | 1535533542 | Python | Python3 | py | Runtime Error | 0 | 0 | 181 | while(True):
n = int(input())
if n == 0: break
for _ in range(n):
m = int(input())
xys = [ map(int,input().split()) for i in range(m) ]
print(1)
|
s534834950 | p00214 | u319725914 | 1535533958 | Python | Python3 | py | Runtime Error | 0 | 0 | 181 | while(True):
n = int(input())
if n == 0: break
for _ in range(n):
m = int(input())
xys = [ map(str,input().split()) for i in range(m) ]
print(1)
|
s169870532 | p00214 | u319725914 | 1535534057 | Python | Python3 | py | Runtime Error | 0 | 0 | 181 | while(True):
n = int(input())
if n == 0: break
for i in range(n):
m = int(input())
xys = [ map(str,input().split()) for i in range(m) ]
print(1)
|
s445358355 | p00214 | u319725914 | 1535534099 | Python | Python3 | py | Runtime Error | 0 | 0 | 164 | while(True):
n = int(input())
if n == 0: break
for i in range(n):
m = int(input())
xys = [ input() for i in range(m) ]
print(1)
|
s439714284 | p00214 | u319725914 | 1535534627 | Python | Python3 | py | Runtime Error | 0 | 0 | 164 | while(True):
n = int(input())
if n == 0: break
for j in range(n):
m = int(input())
xys = [ input() for i in range(m) ]
print(1)
|
s667039808 | p00214 | u319725914 | 1535535062 | Python | Python3 | py | Runtime Error | 0 | 0 | 147 | while(True):
n = int(input())
if n == 0: break
for j in range(n):
m = int(input())
xys = [ input() for i in range(m) ]
|
s596554721 | p00214 | u319725914 | 1535540557 | Python | Python3 | py | Runtime Error | 0 | 0 | 167 | while(True):
n = int(input())
if n == 0: break
for j in range(n):
m = int(input())
xys = [ [input() for k in range(4)] for i in range(m) ]
|
s652552320 | p00214 | u319725914 | 1535540576 | Python | Python3 | py | Runtime Error | 0 | 0 | 167 | while(True):
n = int(input())
if n == 0: break
for j in range(n):
m = int(input())
xys = [ [input() for k in range(8)] for i in range(m) ]
|
s916898280 | p00214 | u319725914 | 1535540597 | Python | Python3 | py | Runtime Error | 0 | 0 | 167 | while(True):
n = int(input())
if n == 0: break
for j in range(n):
m = int(input())
xys = [ [input() for k in range(2)] for i in range(m) ]
|
s449549545 | p00214 | u319725914 | 1535540715 | Python | Python3 | py | Runtime Error | 0 | 0 | 186 | while(True):
n = int(input())
if n == 0: break
for j in range(n):
m = int(input())
xys = [ [input() for k in range(4)] for i in range(m) ]
print(xys)
|
s544812741 | p00214 | u319725914 | 1535540753 | Python | Python3 | py | Runtime Error | 0 | 0 | 186 | while(True):
n = int(input())
if n == 0: break
for j in range(n):
m = int(input())
xys = [ [input() for k in range(4)] for i in range(m) ]
print("1")
|
s668420308 | p00214 | u319725914 | 1535548213 | Python | Python3 | py | Runtime Error | 0 | 0 | 187 | while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
xys = [ list(map(int, input().split())) for i in range(m) ]
print(1)
|
s931630187 | p00214 | u319725914 | 1535548278 | Python | Python3 | py | Runtime Error | 0 | 0 | 198 | while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
for i in range(m):
hoge = list(map(int, input().split()))
print(1)
|
s058083038 | p00214 | u319725914 | 1535636833 | Python | Python3 | py | Runtime Error | 0 | 0 | 198 | while(True):
n = int(input())
if not n: break
for _ in range(n):
m = int(input())
for i in range(m):
hoge = list(map(int, input().split()))
print(1)
|
s552877007 | p00214 | u319725914 | 1535636905 | Python | Python3 | py | Runtime Error | 0 | 0 | 236 | while(True):
try:
n = int(input())
except:
break
if not n: break
for _ in range(n):
m = int(input())
for i in range(m):
hoge = list(map(int, input().split()))
print(1)
|
s251769033 | p00214 | u319725914 | 1535637049 | Python | Python3 | py | Runtime Error | 0 | 0 | 225 | while(True):
try:
n = int(input())
except:
break
if not n: break
for _ in range(n):
m = int(input())
hoge = [list(map(int, input().split())) for j in range(m)]
print(1)
|
s509607758 | p00214 | u319725914 | 1535637676 | Python | Python3 | py | Runtime Error | 0 | 0 | 227 | while(True):
try:
n = int(input())
except:
break
if not n: break
for _ in range(n):
m = int(input())
hoge = [list(map(int, input().split())) for j in range(m)]
print("1")
|
s858045796 | p00214 | u319725914 | 1535637709 | Python | Python3 | py | Runtime Error | 0 | 0 | 276 | from sys import stdin
while(True):
try:
n = int(stdin.readline())
except:
break
if not n: break
for _ in range(n):
m = int(stdin.readline())
hoge = [list(map(int, stdin.readline().split())) for j in range(m)]
print("1")
|
s870835065 | p00214 | u319725914 | 1535638243 | Python | Python3 | py | Runtime Error | 0 | 0 | 305 | from sys import stdin
while(True):
try:
n = int(stdin.readline())
except:
break
if not n: break
for _ in range(n):
m = int(stdin.readline())
try: hoge = [list(map(int, stdin.readline().split())) for j in range(m)]
except: break
print("1")
|
s306139888 | p00214 | u319725914 | 1535638328 | Python | Python3 | py | Runtime Error | 0 | 0 | 306 | from sys import stdin
while(True):
try:
n = int(stdin.readline())
except:
break
if not n: break
for _ in range(n):
m = int(stdin.readline())
try: hoge = [list(map(int, stdin.readline().split())) for j in range(m)]
except: excit()
print("1")
|
s811674355 | p00214 | u319725914 | 1535638386 | Python | Python3 | py | Runtime Error | 0 | 0 | 323 | from sys import stdin
stdin.readline()
while(True):
try:
n = int(stdin.readline())
except:
break
if not n: break
for _ in range(n):
m = int(stdin.readline())
try: hoge = [list(map(int, stdin.readline().split())) for j in range(m)]
except: excit()
print("1")
|
s057874300 | p00214 | u319725914 | 1535638448 | Python | Python3 | py | Runtime Error | 0 | 0 | 322 | from sys import stdin
stdin.readline()
while(True):
try:
n = int(stdin.readline())
except:
break
if not n: break
for _ in range(n):
m = int(stdin.readline())
try: hoge = [list(map(int, stdin.readline().split())) for j in range(m)]
except: exit()
print("1")
|
s747101886 | p00214 | u319725914 | 1535638458 | Python | Python3 | py | Runtime Error | 0 | 0 | 304 | from sys import stdin
while(True):
try:
n = int(stdin.readline())
except:
break
if not n: break
for _ in range(n):
m = int(stdin.readline())
try: hoge = [list(map(int, stdin.readline().split())) for j in range(m)]
except: exit()
print("1")
|
s645868946 | p00214 | u319725914 | 1535639105 | Python | Python3 | py | Runtime Error | 0 | 0 | 309 |
from sys import stdin
while(True):
try:
n = int(stdin.readline())
except:
exit()
if not n: exit()
for _ in range(n):
m = int(stdin.readline())
try: hoge = [list(map(int, stdin.readline().split())) for j in range(m)]
except: exit()
print("1\n")
|
s637568447 | p00214 | u567380442 | 1429250253 | Python | Python3 | py | Runtime Error | 0 | 0 | 1912 | from sys import stdin
readline = stdin.readline
class union_find:
def __init__(self, size):
self.table = [-1 for _ in range(size)]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x == y:
return True
if self.table[y] < self.table[x]:
x, y = y, x
self.table[x] += self.table[y]
self.table[y] = x
return False
def find(self, x):
if self.table[x] < 0:
return x
self.table[x] = self.find(self.table[x])
return self.table[x]
def size(self):
return sum(1 for i in self.table if i < 0)
# p???????????´????????????????????????????¨??????°???
def in_polygon(xy, p):
wn = 0
for i in range(len(p)):
j = i - 1
if 0 == (p[i] - p[j]).imag:
continue
vt = (xy - p[j]).imag / (p[i] - p[j]).imag
tmp = p[j] + vt * (p[i] - p[j])
if xy.real < tmp.real:
wn += 1 if p[j].imag <= xy.imag < p[i].imag else\
-1 if p[i].imag <= xy.imag < p[j].imag else 0
return wn
from itertools import combinations
def solve(cwp):
if len(cwp) == 1:
return 1
ccwp = [pi[::-1] for pi in cwp]
uf = union_find(len(ccwp))
for i, j in combinations(range(len(ccwp)), 2):
if uf.find(i) == uf.find(j):
continue
for ji in ccwp[j]:
if in_polygon(ji, ccwp[i]):
uf.union(i, j)
return uf.size()
def main():
while True:
n = int(readline())
if n == 0:
break
for _ in range(n):
m = int(readline())
cw_polygons = []
for _ in range(m):
l = map(int, readline().split())
cw_p = [complex(real, imag) for real, imag in zip(*[l] * 2)]
cw_polygons.append(cw_p)
print(solve(cw_polygons))
main() |
s819016133 | p00215 | u567380442 | 1429261093 | Python | Python3 | py | Runtime Error | 19930 | 11848 | 1394 | from sys import stdin
readline = stdin.readline
from itertools import product
from collections import defaultdict
from collections import namedtuple
from operator import itemgetter
from math import isinf
Point = namedtuple('Point', 'x y')
def distance(a, b):
return abs(a.x - b.x) + abs(a.y - b.y)
def solve(route, location):
dp = {}
for ri in route:
dp[ri] = [float('inf')] * len(location[ri])
dp['S'][0] = 0
for i in range(len(route) - 1):
s, t = route[i], route[i + 1]
for si, tj in product(range(len(location[s])), range(len(location[t]))):
d = distance(location[s][si], location[t][tj])
if dp[t][tj] > dp[s][si] + d:
dp[t][tj] = dp[s][si] + d
return dp['G'][0]
def main():
while True:
w, h = map(int, readline().split())
if w == 0:
break
field = [readline().strip() for _ in range(h)]
location = defaultdict(list)
for y, x in product(range(h), range(w)):
if field[y][x] != '.':
location[field[y][x]].append(Point(x, y))
element_route = [(i,'S' + ('12345' * 2)[i:i + 4] + 'G') for i in range(1, 6)]
element_move = [(ei, solve(ri, location)) for ei, ri in element_route]
ans = min(element_move, key=itemgetter(1, 0))
print('NA' if isinf(ans[1]) else ' '.join(map(str, ans)))
main() |
s431292899 | p00217 | u104911888 | 1368086034 | Python | Python | py | Runtime Error | 0 | 0 | 195 | while True:
n=input()
if n==0:break
D={}
m=0
for i in range(n):
p,d1,d2=map(int,raw_input().split())
t=d1+d2
m=max(m,t)
D[t]=p
print D[m],m |
s916617507 | p00217 | u104911888 | 1368097259 | Python | Python | py | Runtime Error | 0 | 0 | 197 | while True:
n=input()
if n==0:break
m=0
dic={}
for i in range(n):
p,d1,d2=map(int,raw_input().split())
t=d1+d2
m=max(m,t)
dic[t]=p
print dic[m],m |
s656655911 | p00217 | u918572590 | 1370090737 | Python | Python | py | Runtime Error | 0 | 0 | 433 | def main():
while True:
n=int(raw_input())
if n==0: break;
solve(n)
def solve(n):
a=[]
for _ in range(n):
tmp=map(int,raw_input().split(" "))
a.append(Pair(tmp[0],tmp[1]+tmp[2]))
a.sort()
print a[-1].x, a[-1].y
class Pair:
def __init__(self,x,y):
self.x=x
self.y=y
def __cmp__(self,a):
return self.y-a.y
if __name__=="__main__": main() |
s269932095 | p00217 | u260980560 | 1386572956 | Python | Python | py | Runtime Error | 0 | 0 | 201 | while 1:
n = input()
if n==0: break
pm = -1; m = 0;
for i in xrange(n):
p,d1,d2 = map(int, raw_input().split())
if m<d1+d2:
pm = p; m = d1+d2;
print pm,m |
s274773219 | p00217 | u260980560 | 1386573440 | Python | Python | py | Runtime Error | 0 | 0 | 201 | while 1:
n = input()
if n==0: break
pm = -1; m = -1;
for i in range(n):
p,d1,d2 = map(int, raw_input().split())
if m<d1+d2:
pm = p; m = d1+d2;
print pm,m |
s281004401 | p00217 | u260980560 | 1386573828 | Python | Python | py | Runtime Error | 0 | 0 | 223 | while 1:
n = input()
if n==0: break
l = []
for i in range(n):
p,d1,d2 = map(int, raw_input().split())
l.append([p,d1+d2])
l.sort(reverse=True, key=lambda x:x[1])
print l[0][0],l[0][1] |
s397605359 | p00217 | u633068244 | 1396444107 | Python | Python | py | Runtime Error | 0 | 0 | 162 | while 1:
r={}
n=input()
if n==0:break
for i in [1]*n:
p,d1,d2=map(int,raw_input().split())
r[p]=d1+d2
a=max(r.items(),key=lambda x:x[1])
print a[0],a[1] |
s281759064 | p00217 | u633068244 | 1396444336 | Python | Python | py | Runtime Error | 0 | 0 | 168 | while 1:
try:
r={}
n=input()
l=m=0
for i in [1]*n:
p,d1,d2=map(int,raw_input().split())
d=d1+d2
if d>m:l,m=p,d
print l,m
except syntaxError:
pass |
s132509776 | p00217 | u633068244 | 1396444351 | Python | Python | py | Runtime Error | 0 | 0 | 168 | while 1:
try:
r={}
n=input()
l=m=0
for i in [1]*n:
p,d1,d2=map(int,raw_input().split())
d=d1+d2
if d>m:l,m=p,d
print l,m
except SyntaxError:
pass |
s256745593 | p00218 | u814278309 | 1559138175 | Python | Python3 | py | Runtime Error | 0 | 0 | 499 | n=int(input())
while True:
if n==0:
break
for i in range(n):
m,e,j=map(int,input().split())
if m==100 or e==100 or j==100:
print('{}'.format('A'))
elif (m+e)/2>=90:
print('{}'.format('A'))
elif (m+e+j)/3>=80:
print('{}'.format('A'))
elif (m+e+j)/3>=70:
print('{}'.format('B'))
elif (m+e+j)/3>=50:
if m>=80 or e>=80:
print('{}'.format('B'))
else:
print('{}'.format('C'))
else:
print('{}'.format('C'))
|
s351460119 | p00218 | u647766105 | 1426653991 | Python | Python | py | Runtime Error | 0 | 0 | 412 | while True:
try:
N = input()
except:
break
pm, pe, pj = points = map(int, raw_input())
ave = sum(points) / 3.0
if 100 in points:
print "A"
elif (pm + pe) / 2.0 >= 90:
print "A"
elif ave >= 80:
print "A"
elif ave >= 70:
print "B"
elif ave >= 50 and (pm >= 80 or pe >= 80):
print "B"
else:
print "C"
|
s922236017 | p00218 | u078042885 | 1483523515 | Python | Python3 | py | Runtime Error | 0 | 0 | 292 | while 1:
n=int(input())
if n=='0': break
for _ in range(n):
a=list(map(int,input().split()))
c=sum(a)
if sum(a[:2])/2>=90 or c/3>=80 or 100 in a: b='A'
elif c/3>=70 or (c/3>=50 and (a[0]>=80 or a[1]>=80)): b='B'
else: b='C'
print(b) |
s028022355 | p00218 | u546285759 | 1509356830 | Python | Python3 | py | Runtime Error | 0 | 0 | 505 | while True:
n = int(input())
if n == 0:
break
dataset = [map(int, input().split()) for _ in range(n)]
for map_ in dataset:
pm, pe, pj = map_
x = (pm + pe + pj) // 3
if 100 in p:
print("A")
elif (pm + pe) // 2 >= 90:
print("A")
elif x >= 80:
print("A")
elif x >= 70:
print("B")
elif x >= 50 and (pm >= 80 or pe >= 80):
print("B")
else:
print("C") |
s311382611 | p00218 | u180584272 | 1379839399 | Python | Python | py | Runtime Error | 0 | 0 | 298 | for s in sys.stdin:
s = map(int, s.split())
if len(s)==1:
continue
else:
(pm,pe,pj) = tuple(s)
if 100 in (pm,pe,pj): c = "A"
elif pm+pe>=180: c = "A"
elif pm+pe+pj>=240: c = "A"
elif pm+pe+pj>=240: c = "B"
elif pm+pe+pj>=150 and (pm>=80 or pe>=80): c = "B"
else: c = "C"
print c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.