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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s026578627 | p00155 | u811733736 | 1506924940 | Python | Python3 | py | Runtime Error | 0 | 0 | 2862 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0155
"""
import sys
from sys import stdin
from math import sqrt
input = stdin.readline
def dijkstra(s, G):
BLACK, GRAY, WHITE = 0, 1, 2
d = [float('inf')] * 101
color = [WHITE] * 101
p = [-1] * 101
d[s] = 0
while True:
mincost = float('inf')
# ??\??????????????§??????????????¨?????????????????????u???????????????
for i in range(101):
if color[i] != BLACK and d[i] < mincost: # S????±???????????????????S??¨??\?¶?????????????????????????????????????????°???????????????????
mincost = d[i]
u = i # u??????????????????ID
if mincost == float('inf'):
break
color[u] = BLACK # ?????????u???S????±???????????????´???
for v in range(101):
if color[v] != BLACK and G[u][v] != float('inf'):
# v????????????????????????????????°??????S???????????£???u????????????????????????????????????????????°??????????????±??§??´??°??????
if d[u] + G[u][v] < d[v]:
d[v] = d[u] + G[u][v]
p[v] = u
color[v] = GRAY
return d, p
def main(args):
while True:
n = int(input())
if n == 0:
break
G = [[float('inf')] * (100+1) for _ in range(100+1)]
data = []
for _ in range(n):
b, x, y = map(int, input().split(' '))
data.append([b, x, y])
for i in range(n):
b1, x1, y1 = data[i]
for j in range(n):
b2, x2, y2 = data[j]
if b1 == b2:
continue
dist = sqrt((x1 - x2)**2 + (y1 - y2)**2)
if dist <= 50.0:
G[b1][b2] = dist
G[b2][b1] = dist
m = int(input())
for _ in range(m):
s, g = map(int, input().strip().split(' '))
if s == g:
print(s)
continue
if (not 1<= s <= 100) or (not 1<= g <= 100):
print('NA')
continue
d, p = dijkstra(s, G)
if d[g] == float('inf'):
print('NA')
else:
path = [g]
while p[g] != s:
path.append(p[g])
g = p[g]
path.append(s)
rev = path[::-1]
print(' '.join(map(str, rev)))
def main2(args):
while True:
n = int(input())
if n == 0:
break
for _ in range(n):
input()
m = int(input())
for _ in range(m):
s, g = map(int, input().strip().split(' '))
print('NA')
if __name__ == '__main__':
main(sys.argv[1:]) |
s045262120 | p00155 | u811733736 | 1506925034 | Python | Python3 | py | Runtime Error | 0 | 0 | 2894 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0155
"""
import sys
from sys import stdin
from math import sqrt
input = stdin.readline
def dijkstra(s, G):
BLACK, GRAY, WHITE = 0, 1, 2
d = [float('inf')] * 101
color = [WHITE] * 101
p = [-1] * 101
d[s] = 0
while True:
mincost = float('inf')
# ??\??????????????§??????????????¨?????????????????????u???????????????
for i in range(101):
if color[i] != BLACK and d[i] < mincost: # S????±???????????????????S??¨??\?¶?????????????????????????????????????????°???????????????????
mincost = d[i]
u = i # u??????????????????ID
if mincost == float('inf'):
break
color[u] = BLACK # ?????????u???S????±???????????????´???
for v in range(101):
if color[v] != BLACK and G[u][v] != float('inf'):
# v????????????????????????????????°??????S???????????£???u????????????????????????????????????????????°??????????????±??§??´??°??????
if d[u] + G[u][v] < d[v]:
d[v] = d[u] + G[u][v]
p[v] = u
color[v] = GRAY
return d, p
def main(args):
while True:
n = int(input())
if n == 0:
break
G = [[float('inf')] * (100+1) for _ in range(100+1)]
data = []
for _ in range(n):
b, x, y = map(int, input().split(' '))
data.append([b, x, y])
for i in range(n):
b1, x1, y1 = data[i]
for j in range(n):
b2, x2, y2 = data[j]
if b1 == b2:
continue
dist = sqrt((x1 - x2)**2 + (y1 - y2)**2)
if dist <= 50.0:
G[b1][b2] = dist
G[b2][b1] = dist
m = int(input())
for _ in range(m):
s, g = map(int, input().strip().split(' '))
if s == g:
print(s)
continue
if (not 1<= s <= 100) or (not 1<= g <= 100):
print('NA')
continue
d, p = dijkstra(s, G)
if d[g] == float('inf'):
print('NA')
else:
path = [g]
while p[g] != s:
path.append(p[g])
g = p[g]
path.append(s)
rev = path[::-1]
print(' '.join(map(str, rev)))
def main2(args):
while True:
n = int(input())
if n == 0:
break
for _ in range(n):
b, x, y = map(int, input().split(' '))
m = int(input())
for _ in range(m):
s, g = map(int, input().strip().split(' '))
print('NA')
if __name__ == '__main__':
main2(sys.argv[1:]) |
s987250826 | p00155 | u104911888 | 1383702004 | Python | Python | py | Runtime Error | 0 | 0 | 1423 | import math
def routing(s,g,route):
ans=[]
i=g
while i!=-1:
ans.append(i+1)
i=route[i]
return ans[::-1]
inf=100000
while True:
n=input()
if n==0:break
L=[[inf]*n for i in range(n)]
for i in range(n):
L[i][i]=0
B=[map(int,raw_input().split()) for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
ba,xa,ya=B[i]
bb,xb,yb=B[j]
ba,bb=ba-1,bb-1
d=math.sqrt(pow(xa-xb,2)+pow(ya-yb,2))
if d<=50:
L[ba][bb]=L[bb][ba]=d
m=input()
for p in range(m):
s,g=map(int,raw_input().split())
s,g=s-1,g-1
size=len(L)
done=[s]
dist=[inf]*size
dist[s]=0
route=[-1]*size
i=s
while len(done)<size:
for j in range(size):
if j in done:
continue
if dist[j]>dist[i]+L[i][j]:
dist[j]=dist[i]+L[i][j]
route[j]=i
min_node_size=inf
for v,w in enumerate(dist):
if v not in done and w<min_node_size:
min_node_size=w
min_node_num=v
i=min_node_num
done.append(min_node_num)
if route[g]==-1:
print 'NA'
else:
ans=routing(s,g,route)
print " ".join(map(str,ans)) |
s333288345 | p00155 | u104911888 | 1383702186 | Python | Python | py | Runtime Error | 0 | 0 | 1408 | import math
def routing(s,g,route):
ans=[]
i=g
while i!=-1:
ans.append(i+1)
i=route[i]
return ans[::-1]
inf=100000
while True:
n=input()
if n==0:break
L=[[inf]*n for i in range(n)]
for i in range(n):
L[i][i]=0
B=[map(int,raw_input().split()) for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
ba,xa,ya=B[i]
bb,xb,yb=B[j]
ba,bb=ba-1,bb-1
d=math.sqrt(pow(xa-xb,2)+pow(ya-yb,2))
if d<=50:
L[ba][bb]=L[bb][ba]=d
m=input()
for p in range(m):
s,g=map(int,raw_input().split())
s,g=s-1,g-1
n=len(L)
done=[s]
dist=[inf]*n
dist[s]=0
route=[-1]*n
i=s
while len(done)<n:
for j in range(n):
if j in done:
continue
if dist[j]>dist[i]+L[i][j]:
dist[j]=dist[i]+L[i][j]
route[j]=i
min_node_size=inf
for v,w in enumerate(dist):
if v not in done and w<min_node_size:
min_node_size=w
min_node_num=v
i=min_node_num
done.append(min_node_num)
if dist[g]==inf:
print 'NA'
else:
ans=routing(s,g,route)
print " ".join(map(str,ans)) |
s595125554 | p00155 | u104911888 | 1383702225 | Python | Python | py | Runtime Error | 0 | 0 | 1289 | import math
def routing(s,g,route):
ans=[]
i=g
while i!=-1:
ans.append(i+1)
i=route[i]
return ans[::-1]
inf=100000
while True:
n=input()
if n==0:break
L=[[inf]*n for i in range(n)]
for i in range(n):
L[i][i]=0
B=[map(int,raw_input().split()) for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
ba,xa,ya=B[i]
bb,xb,yb=B[j]
ba,bb=ba-1,bb-1
d=math.sqrt(pow(xa-xb,2)+pow(ya-yb,2))
if d<=50:
L[ba][bb]=L[bb][ba]=d
m=input()
for p in range(m):
s,g=map(int,raw_input().split())
s,g=s-1,g-1
n=len(L)
done=[s]
dist=[inf]*n
dist[s]=0
route=[-1]*n
i=s
while len(done)<n:
for j in range(n):
if j in done:
continue
if dist[j]>dist[i]+L[i][j]:
dist[j]=dist[i]+L[i][j]
route[j]=i
min_node_size=inf
for v,w in enumerate(dist):
if v not in done and w<min_node_size:
min_node_size=w
min_node_num=v
i=min_node_num
done.append(min_node_num)
print 'NA' |
s890769388 | p00158 | u912237403 | 1419626644 | Python | Python | py | Runtime Error | 0 | 0 | 142 | d = {}
while 1:
n = int(raw_input())
if n==0: break
c = 0
while n != 1
if n % 2 ==0: n/=2
else: n = n*3+1
c += 1
print c |
s223242999 | p00158 | u260980560 | 1385146636 | Python | Python | py | Runtime Error | 0 | 0 | 219 | M = 10**6; dp = [-1]*M; dp[0],dp[1] = 0,0;
def collatz(n):
if dp[n]!=-1: return dp[n]
dp[n] = 1+collatz(n/2 if n%2==0 else 3*n+1)
return dp[n]
while 1:
n = input()
if n==0: break
print collatz(n) |
s285140021 | p00160 | u647766105 | 1384837225 | Python | Python | py | Runtime Error | 0 | 0 | 285 | from bisect import bisect,bisect_left
from fractions import gcd
MAXN = 1000002
T = 2**20*3**14*5**9
H = filter(lambda i:gcd(T,i)==i,xrange(MAXN))
while True:
line = raw_input()
if line == "0":
break
m,n = map(int,line.split())
print bisect(H,n)-bisect_left(H,m) |
s699499813 | p00161 | u260980560 | 1501214164 | Python | Python3 | py | Runtime Error | 0 | 0 | 294 | while 1:
n = int(input())
team = []
for _ in range(n):
i, *T = map(int, input().split())
t = 0
for m, s in zip(T[::2], T[1::2]):
t += m*60 + s
team.append((t, i))
team.sort()
print(*[team[0][1], team[1][1], team[-2][1]], sep='\n') |
s211863390 | p00161 | u260980560 | 1501214379 | Python | Python3 | py | Runtime Error | 0 | 0 | 301 | while 1:
n = int(input())
team = []
for _ in range(n):
i, *T = map(int, input().split())
t = 0
for m, s in zip(T[::2], T[1::2]):
t += m*60 + s
team.append((t, i))
team.sort()
print(team[0][1])
print(team[1][1])
print(team[-2][1]) |
s139951710 | p00162 | u260980560 | 1385147655 | Python | Python | py | Runtime Error | 0 | 0 | 313 | num = [2,3,5]
M = 10**6; S = [0]*(M+2); S[1] = 1; s = 0;
for i in xrange(1,M+1):
if S[i]==1:
for j in xrange(3):
S[min(M+1,num[j]*i)] = 1;
s += 1
S[i] = s
while 1:
try:
m,n = map(int, raw_input().split())
print S[n]-S[m-1]
except EOFError:
break |
s148130881 | p00162 | u260980560 | 1385147748 | Python | Python | py | Runtime Error | 0 | 0 | 319 | num = [2,3,5]
M = 10**6; S = [0]*(M+2); S[1] = 1; s = 0;
i = 0;
while(i<M+1):
if S[i]==1:
for j in xrange(3):
S[min(M+1,num[j]*i)] = 1;
s += 1
S[i] = s
i+=1
while 1:
try:
m,n = map(int, raw_input().split())
print S[n]-S[m-1]
except EOFError:
break |
s326372692 | p00162 | u260980560 | 1385148058 | Python | Python | py | Runtime Error | 0 | 0 | 419 | while 1:
try:
n,m = map(int, raw_input().split())
ans = 0
for i in xrange(n,m+1):
p = i
while p>1:
if p%2==0:
p/=2
elif p%3==0:
p/=3
elif p%5==0:
p/=5
else: break
if p==1: ans+=1
print ans
except EOFError:
break |
s404310881 | p00166 | u104911888 | 1369179772 | Python | Python | py | Runtime Error | 0 | 0 | 550 | import math
def inputData(j):
A=[]
t=0
for i in range(j-1):
v=input()
x=math.cos(math.pi*(v+t)/180)
y=math.sin(math.pi*(v+t)/180)
t+=v
A.append((x,y))
A.append(A[0])
return A
def calcArea(A):
return sum((A[i][0]-A[i+1][0])*(A[i][1]+A[i+1][1]) for i in range(m-1))/2
while True:
m=input()
if m==0:break
A=inputData(m)
n=input()
B=inputData(n)
S1,S2=calcArea(A),calcArea(B)
if S1>S2:
print 1
elif S1<S2:
print 2
else:
print 0 |
s915343937 | p00167 | u146816547 | 1506517972 | Python | Python | py | Runtime Error | 0 | 0 | 442 | def bubble_sort(A, N):
flag = True
c = 0
i = 0
while flag:
flag = False
for j in range(N-1, i, -1):
if A[j] < A[j-1]:
A[j], A[j-1] = A[j-1], A[j]
c += 1
flag = True
i += 1
return c
while True:
N = int(raw_input())
if N == 0:
break
A = [map(int, raw_input()) _ for i in range(N)]
print bubble_sort(A, N) |
s839863011 | p00168 | u797636303 | 1559025029 | Python | Python3 | py | Runtime Error | 0 | 0 | 345 | def fib(n):
n=int(n)
F=[1,1,2]
if n>=3:
for j in range(2,n):
F.append(F[j-2]+F[j-1]+F[j])
return F[n]
for i in range(32):
a=input(int())
if a==0:
break
else:
print(-((-fib(a)//10)//365))
#https://python.ms/sub/misc/division/を参考にしました
|
s786118654 | p00168 | u797636303 | 1559025083 | Python | Python3 | py | Runtime Error | 0 | 0 | 345 | def fib(n):
n=int(n)
F=[1,1,2]
if n>=3:
for j in range(2,n):
F.append(F[j-2]+F[j-1]+F[j])
return F[n]
for i in range(32):
a=input(int())
if a==0:
break
else:
print(-((-fib(a)//10)//365))
#https://python.ms/sub/misc/division/を参考にしました
|
s238126588 | p00168 | u797636303 | 1559025358 | Python | Python3 | py | Runtime Error | 0 | 0 | 233 | def fib(n):
n=int(n)
F=[1,1,2]
if n>=3:
for j in range(2,n):
F.append(F[j-2]+F[j-1]+F[j])
return F[n]
a=input(int())
if a==0:
break
else:
print(-((-fib(a)//10)//365))
|
s865591012 | p00168 | u797636303 | 1559025410 | Python | Python3 | py | Runtime Error | 0 | 0 | 203 | def fib(n):
n=int(n)
F=[1,1,2]
if n>=3:
for j in range(2,n):
F.append(F[j-2]+F[j-1]+F[j])
return F[n]
a=input(int())
print(-((-fib(a)//10)//365))
|
s767178206 | p00168 | u529386725 | 1452334286 | Python | Python | py | Runtime Error | 0 | 0 | 244 | #???????????\?????¨??????????????????????????°???
a = [1, 2, 4]
MAX_N = 30
for i in xrange(3, MAX_N+1):
a.append(a[i-3] + a[i-2] + a[i-1])
while True:
n = input()
if n == 0:
break
else:
print a[n-1] / 3650 + 1 |
s001319494 | p00168 | u947762778 | 1508165052 | Python | Python3 | py | Runtime Error | 0 | 0 | 283 | a = []
a[:4] = [0, 1, 2, 3]
inList = []
while True:
price = int(input())
if price == 0:
break
inList.append(int(input()))
n = max(inList)
for i in range(4, n + 1):
a[i] = a[i-1] + a[i-2] + a[i-3]
for i in inList:
print((a[i] // 3650) + (a[i] % 3650 != 0)) |
s320683718 | p00168 | u947762778 | 1508165114 | Python | Python3 | py | Runtime Error | 0 | 0 | 264 | a = []
a[:4] = [0, 1, 2, 3]
inList = []
while True:
n = int(input())
if n == 0:
break
inList.append(n)
n = max(inList)
for i in range(4, n + 1):
a[i] = a[i-1] + a[i-2] + a[i-3]
for i in inList:
print((a[i] // 3650) + (a[i] % 3650 != 0)) |
s635233445 | p00168 | u584093205 | 1526879768 | Python | Python3 | py | Runtime Error | 0 | 0 | 262 | while 1:
n = int(input())
if n == 0:break
A = [1 for _ in range(30)]
for i in range(1, n + 1):
A[i] = A[i - 1]
if i > 1:
A[i] += A[i - 2]
if i > 2:
A[i] += A[i - 3]
print(A[n] // 3650 + 1)
|
s033762781 | p00168 | u584093205 | 1526879809 | Python | Python3 | py | Runtime Error | 0 | 0 | 262 | while 1:
n = int(input())
if n == 0:break
A = [1 for _ in range(30)]
for i in range(1, n + 1):
A[i] = A[i - 1]
if i > 1:
A[i] += A[i - 2]
if i > 2:
A[i] += A[i - 3]
print(A[n] // 3650 + 1)
|
s393501780 | p00168 | u584093205 | 1526879874 | Python | Python3 | py | Runtime Error | 0 | 0 | 262 | while 1:
n = int(input())
if n == 0:break
A = [1 for _ in range(30)]
for i in range(1, n + 1):
A[i] = A[i - 1]
if i > 1:
A[i] += A[i - 2]
if i > 2:
A[i] += A[i - 3]
print(A[n] // 3650 + 1)
|
s538829562 | p00168 | u977698428 | 1397477533 | Python | Python | py | Runtime Error | 0 | 0 | 591 | #coding:utf-8
from __future__ import division,print_function
try:
input = raw_input
except NameError:
pass
# 上記のコードはPython2とPython3の違いを一部吸収するためのもの
memo=[0]*31
def solve(x):
if memo[x]==0:
if x>1:
memo[x]=solve(x-1)+solve(x-2)+solve(x-3)
return memo[x]
elif x==0:
memo[x]=1
return 1
else:
return 0
else:
return memo[x]
def main():
while True:
inp=input()
if inp==0:
break
print(solve(inp))
main() |
s773879893 | p00168 | u708217907 | 1398743414 | Python | Python | py | Runtime Error | 0 | 0 | 202 | import sys, math
step = [1,1,2,4] + [0]*26
for i in range(4,30):
step[i] = step[i-1] + step[i-2] + step[i-3]
for s in sys.stdin:
n = int(s)
if n == 0: break
print int(math.ceil(step[n]/3650.0)) |
s282302819 | p00168 | u708217907 | 1398743537 | Python | Python | py | Runtime Error | 0 | 0 | 202 | import sys, math
step = [1,1,2,4] + [0]*26
for i in range(4,31):
step[i] = step[i-1] + step[i-2] + step[i-3]
for s in sys.stdin:
n = int(s)
if n == 0: break
print int(math.ceil(step[n]/3650.0)) |
s117989403 | p00168 | u708217907 | 1398743699 | Python | Python | py | Runtime Error | 0 | 0 | 189 | import math
step = [1,1,2,4] + [0]*27
for i in range(4,31):
step[i] = step[i-1] + step[i-2] + step[i-3]
while True:
n = int(s)
if n == 0: break
print int(math.ceil(step[n]/3650.0)) |
s797068263 | p00170 | u633068244 | 1397901833 | Python | Python | py | Runtime Error | 0 | 0 | 608 | import itertools
def isOK(array):
for i in range(n-1):
if int(array[i][2])<sum([int(array[i][1]) for x in range(i+1,n)]):
return False
return G(array)
def G(array):
nume=sum([(i+1)*int(array[i][1]) for i in range(n)])*1.0
denomi=sum([int(array[i][1]) for i in range(n)])
return nume/denomi
while 1:
n=input()
if n==0:break
lunch=[raw_input().split() for i in range(n)]
ans,minG=[],10000
for order in itertools.permutations(lunch,n):
print order
val=isOK(order)
if val is not False and val<minG:
ans=[order[i][:] for i in range(n)]
minG=val
for i in range(n):
print ans[i][0] |
s535900571 | p00173 | u460331583 | 1346394685 | Python | Python | py | Runtime Error | 0 | 4956 | 148 | while True:
try:
a,b,c = map(str,raw_input().split())
b,c=a[1],a[2]
print "%s %d %d" %(a,b+c,200*b+300+c)
except EOFError:
break |
s986562024 | p00173 | u460331583 | 1346394930 | Python | Python | py | Runtime Error | 0 | 4956 | 164 | while True:
try:
a = [10000]
a,b,c = map(str,raw_input().split())
b,c=a[1],a[2]
print "%s %d %d" %(a,b+c,200*b+300+c)
except EOFError:
break |
s013504020 | p00173 | u460331583 | 1346394998 | Python | Python | py | Runtime Error | 0 | 4956 | 183 | while True:
try:
a,b,c= [10000],[10000],[10000]
a,b,c = map(str,raw_input().split())
b,c=a[1],a[2]
print "%s %d %d" %(a,b+c,200*b+300+c)
except EOFError:
break |
s852124242 | p00173 | u633068244 | 1396263001 | Python | Python | py | Runtime Error | 0 | 0 | 88 | for i in range(9):
a,b,c = map(int, raw_input().split())
print a,b+c,200*b+300*c |
s034351592 | p00175 | u633068244 | 1396265113 | Python | Python | py | Runtime Error | 0 | 0 | 143 | def f(n):
a = ""
while n>0:
a += str(n%4)
n //= 4
return a[::-1]
while 1:
n = input()
if n == -1: break
print f(n) if n > 0 else 0 |
s330881806 | p00178 | u352394527 | 1531027199 | Python | Python3 | py | Runtime Error | 0 | 0 | 1200 | end = [1,1,1,1,1]
while True:
n = int(input())
if n == 0:
break
mp = [[0] * 5 for _ in range(4000)]
height = [0] * 5
cnt = 0
for i in range(n):
d, p, q = map(int, input().split())
q -= 1
cnt += p
if d == 1:
pos = max(height[q:q + p])
mp[pos][q:q + p] = [1] * p
if mp[pos] == end:
cnt -= 5
mp.pop(pos)
mp.append([0] * 5)
for x in range(5):
for y in range(i * 5 - 1, -1, -1):
if mp[y][x] == 1:
height[x] = y + 1
break
else:
height[x] = 0
else:
height[q:q + p] = [pos + 1] * p
if d == 2:
pop_flag = False
pos = height[q]
for y in range(pos, pos + p):
mp[y][q] = 1
for y in range(pos + p - 1, pos - 1, -1):
if mp[y] == end:
cnt -= 5
mp.pop(y)
mp.append([0] * 5)
pop_flag = True
if pop_flag:
for x in range(5):
for y in range(i * 5 - 1, -1, -1):
if mp[y][x] == 1:
height[x] = y + 1
break
else:
height[x] = 0
else:
height[q] += p
print(cnt)
|
s682480977 | p00178 | u300946041 | 1447322731 | Python | Python | py | Runtime Error | 0 | 0 | 517 | N = raw_input()
while True:
ls = [[None] * 5] * 5000
flwr = 0
for _ in xrange(N):
d, l, pos = raw_input.split()
# block
if d == 1:
for i in xrange(l):
ls[flwr][pos].append(1)
else:
tmp = 0
for i in xrange(l):
ls[flwr][pos+tmp].append(1)
tmp += 1
# up flower
if not None in ls[0]:
flwr += 1
N = raw_input()
# end condition
if not N:
break |
s179602216 | p00178 | u300946041 | 1447322878 | Python | Python | py | Runtime Error | 0 | 0 | 509 | N = input()
while True:
ls = [[None] * 5] * 5000
flwr = 0
for _ in xrange(N):
d, l, pos = raw_input.split()
# block
if d == 1:
for i in xrange(l):
ls[flwr][pos].append(1)
else:
tmp = 0
for i in xrange(l):
ls[flwr][pos+tmp].append(1)
tmp += 1
# up flower
if not None in ls[0]:
flwr += 1
N = input()
# end condition
if not N:
break |
s801245572 | p00178 | u300946041 | 1447323517 | Python | Python | py | Runtime Error | 0 | 0 | 597 | N = input()
while True:
ls = [[None] * 5] * 5000
flwr = 0
for _ in xrange(N):
d, l, pos = raw_input.split()
# block
if d == 1:
for i in xrange(l):
ls[flwr][pos].append(1)
else:
tmp = 0
for i in xrange(l):
ls[flwr][pos+tmp].append(1)
tmp += 1
# up flower
if not None in ls[0]:
flwr += 1
ret = 0
for i in xrange(flwr):
ret += len([i for i in ls[i] if not None])
N = input()
# end condition
if not N:
break |
s987408659 | p00178 | u300946041 | 1447323913 | Python | Python | py | Runtime Error | 0 | 0 | 619 | N = int(input())
while True:
ls = [[None] * 5] * 5000
flwr = 0
for _ in xrange(N):
d, l, pos = map(int, raw_input().split())
# block
if d == 1:
for i in xrange(l):
ls[flwr][pos].append(1)
else:
tmp = 0
for i in xrange(l):
ls[flwr][pos+tmp].append(1)
tmp += 1
# up flower
if not None in ls[0]:
flwr += 1
ret = 0
for i in xrange(flwr):
ret += len([i for i in ls[i] if not None])
N = int(input())
# end condition
if not N:
break |
s187441808 | p00178 | u300946041 | 1447325657 | Python | Python | py | Runtime Error | 0 | 0 | 659 | #!/usr/local/bin/python
N = int(input())
while True:
ls = [[None] * 5] * 5000
flwr = 0
for _ in xrange(N):
d, l, pos = map(int, raw_input().split())
# block
if d == 1:
for i in xrange(l):
ls[flwr][pos].append(1)
else:
tmp = 0
for i in xrange(l):
ls[flwr][pos+tmp].append(1)
tmp += 1
# up flower
if not None in ls[0]:
flwr += 1
ret = 0
for i in xrange(flwr):
ret += len([i for i in ls[i] if not None])
print ret
N = int(input())
# end condition
if not N:
break |
s514478258 | p00178 | u300946041 | 1447332201 | Python | Python | py | Runtime Error | 0 | 0 | 651 | #!/usr/local/bin/python
def init():
return [[None] * 5] * 5000
while True:
N = int(input())
if N == 0:
break
d, l, pos = [int(n) for n in raw_input().split()]
lst = init()
flwr = 0
pos -= 1
for _ in xrange(N):
if d == 1:
for i in xrange(l):
lst[flwr][pos + i] = 1
else:
tmp = 0
for i in xrange(l):
lst[flwr + tmp][pos] = 1
tmp += 1
if not None in lst[flwr]:
flwr += 1
print flwr
ret = 0
for i in xrange(flwr):
ret += len([i for i in lst[i] if not None])
print ret |
s006626402 | p00178 | u300946041 | 1447336433 | Python | Python | py | Runtime Error | 0 | 0 | 786 | #!/usr/local/bin/python
from itertools import islice
def init():
return [[None] * 5] * 5000
N = 4
while True:
#N = int(input())
if N == 0:
break
d, l, pos = [int(n) for n in raw_input().split()]
lst = init()
flwr = 0
for i in xrange(N):
print d, l, pos
# if d == 1:
# for i in xrange(l):
# lst[flwr][pos-1 + i] = 1
# else:
# tmp = 0
# for i in xrange(l):
# lst[flwr + tmp][pos-1] = 1
# tmp += 1
#print lst[flwr]
#print not None in lst[flwr]
if not None in lst[flwr]:
flwr += 1
ret = 0
for i in xrange(flwr):
ret += len([i for i in lst[i] if not None])
#print ret
N -= 1
break |
s927128248 | p00178 | u633068244 | 1397740634 | Python | Python | py | Runtime Error | 0 | 0 | 682 | while 1:
n=input()
if n==0:break
hmax=1000
block=[map(int,raw_input().split()) for i in range(n)]
field=[[0]*5 for i in range(hmax)]
for d,p,q in block:
if d==1:
for li in range(hmax-1,-1,-1):
if field[li][q-1:q+p-1]!=[0]*p:
field[li+1][q-1:q+p-1]=[1]*p
break
else:
field[0][q-1:q+p-1]=[1]*p
else:
for li in range(hmax-1,-1,-1):
if field[li][q-1]!=0:
for i in range(p):
field[li+i+1][q-1]=1
break
else:
for i in range(p):
field[li+i][q-1]=1
i=0
while 1:
if field[i]==[1]*5:
del field[i]
hmax-=1
elif field[i]==[0]*5:
break
else:
i+=1
print sum([sum(field[li]) for li in range(hmax)]) |
s339297976 | p00178 | u633068244 | 1397740920 | Python | Python | py | Runtime Error | 0 | 0 | 644 | while 1:
n=input()
if n==0:break
hmax=10000
block=[map(int,raw_input().split()) for i in range(n)]
field=[[0]*5 for i in range(hmax)]
h=0
for d,p,q in block:
if d==1:
for li in range(h+1,-2,-1):
if field[li][q-1:q+p-1]!=[0]*p or li==-1:
field[li+1][q-1:q+p-1]=[1]*p
h=max(h,li+1)
break
else:
for li in range(h+1,-2,-1):
if field[li][q-1]!=0 or li==-1:
for i in range(p):
field[li+i+1][q-1]=1
h=max(h,li+1+q)
break
i=0
while 1:
if field[i]==[1]*5:
del field[i]
h-=1
elif field[i]==[0]*5:
break
else:
i+=1
print sum([sum(field[li]) for li in range(hmax)]) |
s389419921 | p00178 | u633068244 | 1397741237 | Python | Python | py | Runtime Error | 0 | 0 | 636 | while 1:
n=input()
if n==0:break
hmax=5000
block=[map(int,raw_input().split()) for i in range(n)]
field=[[0]*5 for i in range(hmax)]
h=0
for d,p,q in block:
if d==1:
for li in range(h,-2,-1):
if field[li][q-1:q+p-1]!=[0]*p or li==-1:
field[li+1][q-1:q+p-1]=[1]*p
h=max(h,li+2)
break
else:
for li in range(h,-2,-1):
if field[li][q-1]!=0 or li==-1:
for i in range(p):
field[li+i+1][q-1]=1
h=max(h,li+1+p)
break
i=0
while 1:
if field[i]==[1]*5:
del field[i]
h-=1
elif field[i]==[0]*5:
break
else:
i+=1
print sum([sum(field[li]) for li in range(h)]) |
s289020451 | p00179 | u869924057 | 1521198372 | Python | Python3 | py | Runtime Error | 0 | 0 | 1801 | from collections import deque
import copy
def another_color(a, b):
if a == 'r' and b == 'g' or a == 'g' and b == 'r':
return 'b'
if a == 'r' and b == 'b' or a == 'b' and b == 'r':
return 'g'
if a == 'g' and b == 'b' or a == 'b' and b == 'g':
return 'r'
return None
def is_all_same_elements(es):
return all([e == es[0] for e in es[1:]]) if es else False
class State:
def __init__(self, sequence):
self.colors = list(sequence)
self.label = sequence
self.depth = 0
def nextStates(self):
nextStates = []
for i in range(1, len(self.colors)):
if self.colors[i] != self.colors[i - 1]:
c = another_color(self.colors[i], self.colors[i - 1])
if c is None:
continue
newColors = copy.copy(self.colors)
newColors[i] = c
newColors[i - 1] = c
nextStates.append(State(''.join(newColors)))
return nextStates
def print(self):
print(self.depth)
# for debug
# print("{} {}".format(self.label, self.depth))
sequence = input()
while sequence != '0':
root = State(sequence)
printed = False
visited = [root.label]
queue = deque([])
queue.append(root)
# BFS
while queue:
state = queue.popleft()
if is_all_same_elements(state.colors):
state.print()
printed = True
break
for nextState in state.nextStates():
if not nextState.label in visited:
visited.append(nextState.label)
nextState.depth = state.depth + 1
queue.append(nextState)
if not printed:
print("NA")
# 次の行へ
sequence = input()
|
s924774811 | p00179 | u869924057 | 1521683492 | Python | Python3 | py | Runtime Error | 0 | 0 | 1634 | from collections import deque
import copy
def another_color(a, b):
if not a == 'r' and not b == 'r':
return 'r'
if not a == 'g' and not b == 'g':
return 'g'
return 'b'
def is_all_same_elements(es):
return all([e == es[0] for e in es[1:]]) if es else False
class State:
def __init__(self, sequence):
self.colors = list(sequence)
self.label = sequence
self.depth = 0
def nextStates(self):
nextStates = []
for i in range(1, len(self.colors)):
if self.colors[i] != self.colors[i - 1]:
c = another_color(self.colors[i], self.colors[i - 1])
newColors = copy.copy(self.colors)
newColors[i] = c
newColors[i - 1] = c
nextStates.append(State(''.join(newColors)))
return nextStates
def print(self):
print(self.depth)
# for debug
# print("{} {}".format(self.label, self.depth))
sequence = input()
while sequence != '0':
root = State(sequence)
printed = False
visited = [root.label]
queue = deque([])
queue.append(root)
# BFS
while queue:
state = queue.popleft()
if is_all_same_elements(state.colors):
state.print()
printed = True
break
for nextState in state.nextStates():
if not nextState.label in visited:
visited.append(nextState.label)
nextState.depth = state.depth + 1
queue.append(nextState)
if not printed:
print("NA")
# 次の行へ
sequence = input()
|
s459652299 | p00179 | u869924057 | 1521684136 | Python | Python3 | py | Runtime Error | 0 | 0 | 1675 | import sys
sys.setrecursionlimit(100000)
from collections import deque
import copy
def another_color(a, b):
if not a == 'r' and not b == 'r':
return 'r'
if not a == 'g' and not b == 'g':
return 'g'
return 'b'
def is_all_same_elements(es):
return all([e == es[0] for e in es[1:]]) if es else False
class State:
def __init__(self, sequence):
self.colors = list(sequence)
self.label = sequence
self.depth = 0
def nextStates(self):
nextStates = []
for i in range(1, len(self.colors)):
if self.colors[i] != self.colors[i - 1]:
c = another_color(self.colors[i], self.colors[i - 1])
newColors = copy.copy(self.colors)
newColors[i] = c
newColors[i - 1] = c
nextStates.append(State(''.join(newColors)))
return nextStates
def print(self):
print(self.depth)
# for debug
# print("{} {}".format(self.label, self.depth))
sequence = input()
while sequence != '0':
root = State(sequence)
printed = False
visited = [root.label]
queue = deque([])
queue.append(root)
# BFS
while queue:
state = queue.popleft()
if is_all_same_elements(state.colors):
state.print()
printed = True
break
for nextState in state.nextStates():
if not nextState.label in visited:
visited.append(nextState.label)
nextState.depth = state.depth + 1
queue.append(nextState)
if not printed:
print("NA")
# 次の行へ
sequence = input()
|
s700890162 | p00179 | u869924057 | 1521684182 | Python | Python3 | py | Runtime Error | 0 | 0 | 1634 | from collections import deque
import copy
def another_color(a, b):
if not a == 'r' and not b == 'r':
return 'r'
if not a == 'g' and not b == 'g':
return 'g'
return 'b'
def is_all_same_elements(es):
return all([e == es[0] for e in es[1:]]) if es else False
class State:
def __init__(self, sequence):
self.colors = list(sequence)
self.label = sequence
self.depth = 0
def nextStates(self):
nextStates = []
for i in range(1, len(self.colors)):
if self.colors[i] != self.colors[i - 1]:
c = another_color(self.colors[i], self.colors[i - 1])
newColors = copy.copy(self.colors)
newColors[i] = c
newColors[i - 1] = c
nextStates.append(State(''.join(newColors)))
return nextStates
def print(self):
print(self.depth)
# for debug
# print("{} {}".format(self.label, self.depth))
sequence = input()
while sequence != '0':
root = State(sequence)
printed = False
visited = [root.label]
queue = deque([])
queue.append(root)
# BFS
while queue:
state = queue.popleft()
if is_all_same_elements(state.colors):
state.print()
printed = True
break
for nextState in state.nextStates():
if not nextState.label in visited:
visited.append(nextState.label)
nextState.depth = state.depth + 1
queue.append(nextState)
if not printed:
print("NA")
# 次の行へ
sequence = input()
|
s137148665 | p00179 | u921825999 | 1521718458 | Python | Python | py | Runtime Error | 0 | 0 | 1632 | from collections import deque
import copy
def another_color(a, b):
if not a == 'r' and not b == 'r':
return 'r'
if not a == 'g' and not b == 'g':
return 'g'
return 'b'
def is_all_same_elements(es):
return all([e == es[0] for e in es[1:]]) if es else False
class State:
def __init__(self, sequence):
self.colors = list(sequence)
self.label = sequence
self.depth = 0
def nextStates(self):
nextStates = []
for i in range(1, len(self.colors)):
if self.colors[i] != self.colors[i - 1]:
c = another_color(self.colors[i], self.colors[i - 1])
newColors = copy.copy(self.colors)
newColors[i] = c
newColors[i - 1] = c
nextStates.append(State(''.join(newColors)))
return nextStates
def show(self):
print(self.depth)
# for debug
# print("{} {}".format(self.label, self.depth))
sequence = input()
while sequence != '0':
root = State(sequence)
printed = False
visited = [root.label]
queue = deque([])
queue.append(root)
# BFS
while queue:
state = queue.popleft()
if is_all_same_elements(state.colors):
state.show()
printed = True
break
for nextState in state.nextStates():
if not nextState.label in visited:
visited.append(nextState.label)
nextState.depth = state.depth + 1
queue.append(nextState)
if not printed:
print("NA")
# 次の行へ
sequence = input()
|
s162216946 | p00179 | u921825999 | 1521718486 | Python | Python | py | Runtime Error | 0 | 0 | 1632 | from collections import deque
import copy
def another_color(a, b):
if not a == 'r' and not b == 'r':
return 'r'
if not a == 'g' and not b == 'g':
return 'g'
return 'b'
def is_all_same_elements(es):
return all([e == es[0] for e in es[1:]]) if es else False
class State:
def __init__(self, sequence):
self.colors = list(sequence)
self.label = sequence
self.depth = 0
def nextStates(self):
nextStates = []
for i in range(1, len(self.colors)):
if self.colors[i] != self.colors[i - 1]:
c = another_color(self.colors[i], self.colors[i - 1])
newColors = copy.copy(self.colors)
newColors[i] = c
newColors[i - 1] = c
nextStates.append(State(''.join(newColors)))
return nextStates
def show(self):
print(self.depth)
# for debug
# print("{} {}".format(self.label, self.depth))
sequence = input()
while sequence != '0':
root = State(sequence)
printed = False
visited = [root.label]
queue = deque([])
queue.append(root)
# BFS
while queue:
state = queue.popleft()
if is_all_same_elements(state.colors):
state.show()
printed = True
break
for nextState in state.nextStates():
if not nextState.label in visited:
visited.append(nextState.label)
nextState.depth = state.depth + 1
queue.append(nextState)
if not printed:
print("NA")
# 次の行へ
sequence = input()
|
s634853276 | p00179 | u921825999 | 1521718499 | Python | Python3 | py | Runtime Error | 0 | 0 | 1632 | from collections import deque
import copy
def another_color(a, b):
if not a == 'r' and not b == 'r':
return 'r'
if not a == 'g' and not b == 'g':
return 'g'
return 'b'
def is_all_same_elements(es):
return all([e == es[0] for e in es[1:]]) if es else False
class State:
def __init__(self, sequence):
self.colors = list(sequence)
self.label = sequence
self.depth = 0
def nextStates(self):
nextStates = []
for i in range(1, len(self.colors)):
if self.colors[i] != self.colors[i - 1]:
c = another_color(self.colors[i], self.colors[i - 1])
newColors = copy.copy(self.colors)
newColors[i] = c
newColors[i - 1] = c
nextStates.append(State(''.join(newColors)))
return nextStates
def show(self):
print(self.depth)
# for debug
# print("{} {}".format(self.label, self.depth))
sequence = input()
while sequence != '0':
root = State(sequence)
printed = False
visited = [root.label]
queue = deque([])
queue.append(root)
# BFS
while queue:
state = queue.popleft()
if is_all_same_elements(state.colors):
state.show()
printed = True
break
for nextState in state.nextStates():
if not nextState.label in visited:
visited.append(nextState.label)
nextState.depth = state.depth + 1
queue.append(nextState)
if not printed:
print("NA")
# 次の行へ
sequence = input()
|
s820140720 | p00180 | u873482706 | 1436626492 | Python | Python | py | Runtime Error | 0 | 0 | 755 | def f(n, ans):
for k, c in dic.items():
a, b = k
if a == n:
if not b in cost or c < cost[b]:
cost[b] = c
elif b == n:
if not a in cost or c < cost[a]:
cost[a] = c
for k, c in sorted(cost.items(), key=lambda x: x[1]):
if not k in res:
res.append(k)
ans += c
del dic[k]
return f(k, ans)
return ans
while True:
n, m = map(int, raw_input().split())
if n == m == 0: break
dic = {}
s, b, c = map(int, raw_input().split())
dic[(s, b)] = c
for i in range(m-1):
a, b, c = map(int, raw_input().split())
dic[(a, b)] = c
cost = {}
res = [s]
print f(s, 0) |
s465955772 | p00180 | u873482706 | 1437024275 | Python | Python | py | Runtime Error | 0 | 0 | 659 | def f(s, cost, route, ans):
route.append(s)
ans += cost[s]
del cost[s]
for k, c in data.items():
if s in k:
a, b = k
b = b if s == a else a
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
if cost:
s = sorted(cost.items(), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans)
else:
return ans
while True:
n, m = map(int, raw_input().split())
if n == m == 0: break
data = {}
for i in range(m):
a, b, c = map(int, raw_input().split())
data[(a, b)] = c
else:
print f(0, {0:0}, [], 0) |
s351507261 | p00180 | u873482706 | 1437025075 | Python | Python | py | Runtime Error | 0 | 0 | 714 | def f(s, cost, route, ans):
route.append(s)
ans += cost[s]
del cost[s]
for k, c in data.items():
if s in k:
a, b = k
a, b = a, b if s == a else b, a
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
del data[(a, b)]
if cost:
s = sorted(cost.items(), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans)
return ans
while 1:
n, m = map(int, raw_input().split())
if n == m == 0: break
data = {}
for i in range(m):
a, b, c = map(int, raw_input().split())
data[(a, b)] = c
print f(0, {0:0}, [], 0) |
s596828231 | p00180 | u873482706 | 1437025304 | Python | Python | py | Runtime Error | 0 | 0 | 750 | import copy
def f(s, cost, route, ans, data):
route.append(s)
ans += cost[s]
del cost[s]
_data = copy.deepcopy(data)
for k, c in _data.items():
if s in k:
a, b = k
a, b = a, b if s == a else b, a
if not b in route:
if not b in cost or c < cost[b]:
cost[b] = c
del data[(a, b)]
if cost:
s = sorted(cost.items(), key=lambda x: x[1])[0][0]
return f(s, cost, route, ans, data)
return ans
while 1:
n, m = map(int, raw_input().split())
if n == m == 0: break
data = {}
for i in range(m):
a, b, c = map(int, raw_input().split())
data[(a, b)] = c
print f(0, {0:0}, [], 0, data) |
s084568568 | p00181 | u873482706 | 1436689421 | Python | Python | py | Runtime Error | 0 | 0 | 525 | while True:
m, n = map(int, raw_input().split())
if m == n == 0: break
tl = 0
book = []
for i in range(n):
l = input()
tl += l
book.append(l)
else:
pe = float(tl)/m
ll = 0
c = 1
for i, length in enumerate(book):
ll += length
if pe <= ll:
if ll <= float(sum(book[i:]))/(m-c):
pe = ll
else:
pe = float(sum(book[i:]))/(m-c)
ll = 0
c += 1
else:
print pe |
s199164298 | p00181 | u873482706 | 1436689666 | Python | Python | py | Runtime Error | 0 | 0 | 570 | while True:
m, n = map(int, raw_input().split())
if m == n == 0: break
tl = 0
book = []
for i in range(n):
l = input()
tl += l
book.append(l)
else:
pe = float(tl)/m
ll = 0
c = 1
for i, length in enumerate(book):
ll += length
if pe <= ll and m != 0:
if ll <= float(sum(book[i:]))/(m-c):
pe = ll
else:
pe = float(sum(book[i:]))/(m-c)
ll = 0
c += 1
else:
pe = ll
else:
print pe |
s196961934 | p00181 | u873482706 | 1436690783 | Python | Python | py | Runtime Error | 0 | 0 | 584 | while True:
m, n = map(int, raw_input().split())
if m == n == 0: break
tl = 0
book = []
for i in range(n):
l = input()
tl += l
book.append(l)
else:
pe = float(tl)/m
if m == 1:
print int(pe)
continue
ll = 0
c = 1
for i, length in enumerate(book):
ll += length
if pe <= ll:
if ll <= float(sum(book[i:]))/(m-c):
pe = ll
else:
pe = float(sum(book[i:]))/(m-c)
ll = 0
c += 1
else:
print int(pe) |
s578762562 | p00181 | u873482706 | 1436693962 | Python | Python | py | Runtime Error | 0 | 0 | 607 | while True:
m, n = map(int, raw_input().split())
if m == n == 0: break
tl = 0
book = []
for i in range(n):
l = input()
tl += l
book.append(l)
else:
pe = float(tl)/m
ll = []
c = 1
for i, length in enumerate(book):
ll.append(length)
if pe <= sum(ll):
if len(ll) == 1:
pe = sum(ll)
elif ll <= float(sum(book[i:]))/(m-c):
pe = sum(ll)
else:
pe = float(sum(book[i:]))/(m-c)
ll = []
c += 1
else:
print int(pe) |
s346369853 | p00181 | u514808940 | 1457673372 | Python | Python3 | py | Runtime Error | 0 | 0 | 845 |
class Solve:
def __init__(self):
self.M, self.N = map(int, input().split())
self.bs = [int(input()) for i in range(self.N)]
self.S = min(sum(self.bs), 1500000)
self.l, self.r = 0, self.S
def check(self, W):
w = W
i = 1
for b in self.bs:
if(W < b):
return False
if(w >= b):
w -= b
else:
if(i >= self.M):
return False
else:
i += 1
w = W - b
return True
def solve(self):
while self.r - self.l > 1:
m = (self.l + self.r) // 2
if self.check(m):
self.r = m
else:
self.l = m
return self.r
while True:
print(Solve().solve()) |
s331082747 | p00181 | u514808940 | 1457673558 | Python | Python3 | py | Runtime Error | 0 | 0 | 818 |
class Solve:
def __init__(self):
self.M, self.N = map(int, input().split())
self.bs = [int(input()) for i in range(self.N)]
self.S = min(sum(self.bs), 1500000)
self.l, self.r = 0, self.S
def check(self, W):
w = W
i = 1
for b in self.bs:
if(w >= b):
w -= b
elif(W >= b):
if(i >= self.M):
return False
i += 1
w = W - b
else:
return False
return True
def solve(self):
while self.r - self.l > 1:
m = (self.l + self.r) // 2
if self.check(m):
self.r = m
else:
self.l = m
return self.r
while True:
print(Solve().solve()) |
s908824760 | p00181 | u301729341 | 1495869058 | Python | Python3 | py | Runtime Error | 0 | 0 | 1083 | def nibutan(f_id,e_id,f_num,yn):
m_id = int((f_id + e_id) / 2)
m_num = w_lis[m_id]
if e_id - f_id <= 1:
if yn == 0:
return e_id
else:
return f_id
else:
if m_num > f_num:
return(nibutan(f_id,m_id -1,f_num,yn))
elif m_num < f_num:
return(nibutan(m_id + 1,e_id,f_num,yn))
else:
return m_num
while True:
global w_lis
b_lis = []
w_lis = []
dan_num = [0]
atu_num = [0]
wa = 0
m,n = map(int,input().split())
if m == n == 0:
break
for i in range(n):
num = int(input())
wa += num
b_lis.append(num)
w_lis.append(wa)
best_num = wa / m
if best_num < max(b_lis):
print(max(b_lis))
else:
bid = 0
n_si = 0
for i in range(m):
bid = nibutan(bid,n - 1,n_si + best_num,i)
n_si = w_lis[bid]
dan_num.append(n_si)
atu_num.append(n_si - dan_num[i])
print(max(atu_num))
|
s583236912 | p00183 | u104911888 | 1367481784 | Python | Python | py | Runtime Error | 0 | 0 | 357 | while True:
s=raw_input()
if s=="0":break
s+="".join([raw_input() for i in range(2)])
L=[(i,i+1,i+2) for i in range(0,9,3)]+[(i,i+3,i+6) for i in range(3)]+[tupl\
e(range(0,9,4))]+[tuple(range(2,7,2))]
for i,j,k in L:
if s[i]==s[j]==s[k]:
print "b" if s[i]=="b" else "w"
break
else:
print "NA" |
s261868643 | p00183 | u104911888 | 1367481877 | Python | Python | py | Runtime Error | 0 | 0 | 339 | while True:
s=raw_input()
if s=="0":break
s+="".join([raw_input() for i in range(2)])
L=[(i,i+1,i+2) for i in range(0,9,3)]+
[(i,i+3,i+6) for i in range(3)]+
[(0,4,8),(2,4,6)]
for i,j,k in L:
if s[i]==s[j]==s[k]:
print "b" if s[i]=="b" else "w"
break
else:
print "NA" |
s267287472 | p00184 | u814278309 | 1559164466 | Python | Python3 | py | Runtime Error | 0 | 0 | 427 | n=int(input())
while True:
if n==0:
break
x=[0 for i in range(7)]
for i in range(n):
a=int(input())
if 0<=a<10:
x[0]+=1
elif 10<=a<20:
x[1]+=1
elif 20<=a<30:
x[2]+=1
elif 30<=a<40:
x[3]+=1
elif 40<=a<50:
x[4]+=1
elif 50<=a<60:
x[5]+=1
else:
x[6]+=1
for i in range(7):
if x[i]==0:
print(0)
else:
print('{}'.format(x[i]))
|
s157005347 | p00184 | u814278309 | 1559173483 | Python | Python3 | py | Runtime Error | 0 | 0 | 425 | n=int(input())
x=[0 for i in range(7)]
while True:
if n==0:
break
for i in range(n):
a=int(input())
if 0<=a<10:
x[0]+=1
elif 10<=a<20:
x[1]+=1
elif 20<=a<30:
x[2]+=1
elif 30<=a<40:
x[3]+=1
elif 40<=a<50:
x[4]+=1
elif 50<=a<60:
x[5]+=1
else:
x[6]+=1
for i in range(7):
if x[i]==0:
print(0)
else:
print('{}'.format(x[i]))
|
s083328847 | p00184 | u814278309 | 1559173542 | Python | Python3 | py | Runtime Error | 0 | 0 | 412 | n=int(input())
x=[0 for i in range(7)]
while True:
if n==0:
break
for i in range(n):
a=int(input())
if 0<=a<10:
x[0]+=1
elif 10<=a<20:
x[1]+=1
elif 20<=a<30:
x[2]+=1
elif 30<=a<40:
x[3]+=1
elif 40<=a<50:
x[4]+=1
elif 50<=a<60:
x[5]+=1
else:
x[6]+=1
for i in range(7):
if x[i]==0:
print(0)
else:
print(x[i])
|
s102448187 | p00184 | u812047151 | 1469963121 | Python | Python3 | py | Runtime Error | 0 | 0 | 338 | while True:
n = int(input())
ans = [0 for _ in range(7)]
for _ in range(n):
age = int(input())
if age < 10:
ans[0] += 1
elif age < 20:
ans[1] += 1
elif age < 30:
ans[2] += 1
elif age < 40:
ans[3] += 1
elif age < 50:
ans[4] += 1
elif age < 60:
ans[5] += 1
else:
ans[6] += 1
for a in ans:
print(a) |
s234596117 | p00184 | u621997536 | 1397549841 | Python | Python | py | Runtime Error | 0 | 0 | 312 | #include<algorithm>
#include<iostream>
using namespace std;
int main()
{
while(1)
{
int c[7] = {}, n;
cin >> n;
if(!n)
break;
for(int i = 0; i < n; i++)
{
int a;
cin >> a;
c[min(a / 10, 6)]++;
}
for(int i = 0; i < 7; i++)
cout << c[i] << endl;
}
} |
s817812993 | p00185 | u873482706 | 1436703171 | Python | Python | py | Runtime Error | 0 | 0 | 804 | while True:
m = input()
if m == 0: break
L = [i for i in range(2, m+1)]
p = 2
q = None
ans = []
while L:
_L = L[:]
for n in _L:
if n == p:
ans.append(n)
L.remove(n)
else:
if n % p == 0:
L.remove(n)
c = 1
elif q is None:
q = n
else:
p = q
q = None
c = 0
while ans:
b = ans[0]
for n in sorted(ans, reverse=True):
if b+n == m:
c += 1
ans.remove(n)
del ans[0]
break
elif b+n < m:
del ans[0]
break
else:
break
print c |
s679221125 | p00185 | u811733736 | 1507126295 | Python | Python3 | py | Runtime Error | 0 | 0 | 1207 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0185
"""
import sys
from sys import stdin
from bisect import bisect_left
input = stdin.readline
def create_prime_list(limit):
""" ??¨??????????????????????????§limit?????§????´???°?????????????±???????
https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
"""
x = limit**0.5
primes = []
nums = [x for x in range(2, limit+1)]
while nums[0] <= x:
primes.append(nums[0])
current_prime = nums[0]
nums = [x for x in nums if x % current_prime != 0]
primes.extend(nums)
return primes
def main(args):
primes = create_prime_list(500000)
while True:
# n = 98792
n = int(input())
if n == 0:
break
ans = 0 # ????????????????????????????????°
for i in range(n):
a = primes[i]
if a > n/2:
break
i = bisect_left(primes, n - a)
if i != len(primes) and primes[i] == n-a:
ans += 1
print(ans)
if __name__ == '__main__':
main(sys.argv[1:]) |
s221621329 | p00185 | u808429775 | 1524940104 | Python | Python3 | py | Runtime Error | 0 | 0 | 1108 | import array
import bisect
def is_prime_number(num):
limit = int(num ** 0.5)
for lp in range(3, limit + 1, 2):
if num % lp == 0:
return False
return True
LENGTH = 1000000
prime_number_list = array.array("i", [True] * (LENGTH + 1))
prime_number_list[0] = False
prime_number_list[1] = False
for lp in range(4, LENGTH + 1, 2):
prime_number_list[lp] = False
limit = int((LENGTH + 1) ** 0.5)
for lp in range(3, limit + 1, 2):
if is_prime_number(lp):
for lp2 in range(lp * 2, LENGTH + 1, lp):
prime_number_list[lp2] = False
prime_number_list = array.array("i", [index for index, item in enumerate(prime_number_list) if item])
while True:
input_num = int(input())
if input_num == 0:
break
count = 0
array_size = bisect.bisect_left(prime_number_list, input_num // 2)
for lp in prime_number_list[:array_size + 1]:
search_num = input_num - lp
index = bisect.bisect_left(prime_number_list, search_num)
if prime_number_list[index] == search_num:
count += 1
print(count)
|
s322898441 | p00185 | u808429775 | 1524942222 | Python | Python3 | py | Runtime Error | 0 | 0 | 1361 | import array
import bisect
def is_prime_number(num):
limit = int(num ** 0.5)
for lp in range(3, limit + 1, 2):
if num % lp == 0:
return False
return True
def binary_search(num_list, num):
left = 0
right = len(num_list)
while left <= right:
mid = (left + right) // 2
if num_list[mid] == num:
return True
elif num_list[mid] < num:
left = mid + 1
else:
right = mid - 1
return False
LENGTH = 1000000
prime_number_list = array.array("i", [True] * (LENGTH + 1))
prime_number_list[0] = False
prime_number_list[1] = False
for lp in range(4, LENGTH + 1, 2):
prime_number_list[lp] = False
limit = int((LENGTH + 1) ** 0.5)
for lp in range(3, limit + 1, 2):
if is_prime_number(lp):
for lp2 in range(lp * 2, LENGTH + 1, lp):
prime_number_list[lp2] = False
prime_number_list = array.array("i", [index for index, item in enumerate(prime_number_list) if item])
while True:
input_num = int(input())
if input_num == 0:
break
count = 0
array_size = bisect.bisect_left(prime_number_list, input_num // 2)
for lp in prime_number_list[:array_size + 1]:
search_num = input_num - lp
if binary_search(prime_number_list, search_num):
count += 1
print(count)
|
s786495184 | p00185 | u352394527 | 1529730882 | Python | Python3 | py | Runtime Error | 0 | 0 | 582 | from bisect import bisect_left as bl
def primes(n):
tf = [True] * (n + 1)
tf[0] = tf[1] = False
for i in range(2, int(n ** (1 / 2) + 1)):
if tf[i]:
for j in range(i ** 2, n + 1, i):
tf[j] = False
return [i for i in range(n + 1) if tf[i]]
def search_pair(x, prime_lst):
cnt = 0
for prime in prime_lst:
if prime > x // 2:
break
i = bl(prime_lst, x - prime)
if prime_lst[i] == x - prime:
cnt += 1
return cnt
prime_lst = primes(1000000)
while True:
n = int(input())
if n == 0:
break
print(search_pair(n, prime_lst))
|
s560045312 | p00185 | u621997536 | 1399874459 | Python | Python | py | Runtime Error | 0 | 0 | 329 | MN = 100000
prime = []
mem = [False] * 2 + [True] * MN
for i in range(2, MN):
if not mem[i]:
continue
prime.append(i)
for j in range(i + i, MN, i):
mem[j] = False
while True:
N, ans = input(), 0
if not N:
break
for p in prime:
if p > N / 2:
break
if mem[N - p]:
ans += 1
print(ans) |
s280521608 | p00186 | u043254318 | 1528822780 | Python | Python3 | py | Runtime Error | 0 | 0 | 245 | while True:
N = input()
if N == "0":
break
q1,b,c1,c2,q2 = [int(i) for i in N.split()]
x = min((b-c2*q1) // (c1-c2), q2, b // c1)
y = (b-c1*x) // c2
if x <= 0:
print("NA")
else:
print(x,y)
|
s073683672 | p00188 | u873482706 | 1436771940 | Python | Python | py | Runtime Error | 0 | 0 | 473 | import math
def f(check, n, L, count):
count += 1
median = int(math.floor(float(n)/2))
if len(L) == 1 or L[median] == check:
return count
elif L[median] < check:
L = L[median+1:]
elif check < L[median]:
L = L[:median]
n = len(L)
return f(check, n, L, count)
while True:
n = int(raw_input())
if n == 0: break
L = [int(raw_input()) for i in range(n)]
check = int(raw_input())
print f(check, n-1, L, 0) |
s897334817 | p00188 | u873482706 | 1436772032 | Python | Python | py | Runtime Error | 0 | 0 | 475 | import math
def f(check, n, L, count):
count += 1
median = int(math.floor(float(n)/2))
if len(L) == 1 or L[median] == check:
return count
elif L[median] < check:
L = L[median+1:]
elif check < L[median]:
L = L[:median]
n = len(L)-1
return f(check, n, L, count)
while True:
n = int(raw_input())
if n == 0: break
L = [int(raw_input()) for i in range(n)]
check = int(raw_input())
print f(check, n-1, L, 0) |
s029364596 | p00188 | u873482706 | 1436782847 | Python | Python | py | Runtime Error | 0 | 0 | 501 | import math
def f(check, n, L, count):
count += 1
median = int(math.floor(float(n-1)/2))
if len(L) == 1:
return count
elif L[median] == check:
return count
elif L[median] < check:
L = L[median+1:]
elif check < L[median]:
L = L[:median]
n = len(L)
return f(check, n, L, count)
while True:
n = int(raw_input())
if n == 0: break
L = [int(raw_input()) for i in range(n)]
check = int(raw_input())
print f(check, n, L, 0) |
s039428486 | p00188 | u873482706 | 1436783601 | Python | Python | py | Runtime Error | 0 | 0 | 438 | def f(check, n, L, count):
count += 1
median = (n-1)/2
if len(L) == 1 or L[median] == check:
return count
elif L[median] < check:
L = L[median+1:]
elif check < L[median]:
L = L[:median]
n = len(L)
return f(check, n, L, count)
while True:
n = int(raw_input())
if n == 0: break
L = [int(raw_input()) for i in range(n)]
check = int(raw_input())
print f(check, n, L, 0) |
s177622560 | p00188 | u078042885 | 1486417930 | Python | Python3 | py | Runtime Error | 0 | 0 | 231 | while 1:
l,r=0,int(input())
a=[int(input()) for _ in range(r)]
r-=1;c=0
k=int(input())
while l<=r:
c+=1
m=(l+r)//2
if a[m]==k:break
if a[m]<k:l=m+1
else:r=m-1
print(c) |
s288418878 | p00188 | u301729341 | 1495863827 | Python | Python3 | py | Runtime Error | 0 | 0 | 612 | def nibutan(f_id,e_id,f_num,count):
m_id = int((f_id + e_id) / 2)
m_num = n_lis[m_id]
count += 1
if (f_id > e_id):
return count
else:
if m_num > f_num:
return(nibutan(f_id,m_id -1,f_num,count))
elif m_num < f_num:
return(nibutan(m_id + 1,e_id,f_num,count))
else:
return count
while True:
global n_lis
n = int(input())
if n == 0:
break
n_lis = []
for i in range(n):
n_lis.append(int(input()))
f_n = int(input())
ans = nibutan(0,n,f_n,0)
print(ans) |
s505513713 | p00188 | u133119785 | 1509186571 | Python | Python3 | py | Runtime Error | 0 | 0 | 470 | def search(n,d,t):
b = 0
e = n
r = 0
while True:
r += 1
if b > e:
return r
else:
i = (b+e)//2
if t == d[i]:
return r
elif t < d[i]:
e = i - 1
else:
b = i + 1
while True:
n = int(input())
if n == 0:
break
d = [int(input()) for i in range(n)]
t = int(input())
m = search(n,d,t)
print(m)
|
s143541845 | p00188 | u133119785 | 1509186630 | Python | Python3 | py | Runtime Error | 0 | 0 | 465 | def search(n,d,t):
b = 0
e = n
r = 0
while True:
r += 1
if b > e:
return r
else:
i = (b+e)//2
if t == d[i]:
return r
elif t < d[i]:
e = i - 1
else:
b = i + 1
while True:
n = int(input())
if n == 0:
break
d = [int(input()) for i in range(n)]
t = int(input())
m = search(n,d,t)
print(m) |
s996292216 | p00188 | u633068244 | 1399013843 | Python | Python | py | Runtime Error | 0 | 0 | 214 | while 1:
n = input()
if n == 0: break
N = [int(raw_input()) for i in range(n)]
s = input()
i = n/2
c = 1
while i > 0:
c += 1
if N[i] == s:
break
elif N[i] < s:
i /= 2
else:
i += i/2
print c |
s591909962 | p00189 | u695154284 | 1492094877 | Python | Python3 | py | Runtime Error | 0 | 0 | 1048 | def solve(_dp, _v):
for k in range(0, _v + 1):
for i in range(0, _v + 1):
for j in range(0, _v + 1):
_dp[i][j] = min(_dp[i][j], _dp[i][k] + _dp[k][j])
return _dp
if __name__ == '__main__':
while True:
n = int(input())
if n == 0: break
dp = [[100000] * 10 for i in range(10)]
v = 0
for i in range(0, n):
dp[i][i] = 0
inputs = list(map(int, input().split()))
dp[inputs[0]][inputs[1]] = inputs[2]
dp[inputs[1]][inputs[0]] = inputs[2]
if v < inputs[0]:
v = inputs[0]
if v < inputs[1]:
v = inputs[1]
dp = solve(dp, v)
ans_town = 0
ans_dis = float("inf")
for i in range(0, v + 1):
tmp_sum = 0
for j in range(0, v + 1):
tmp_sum += dp[i][j]
if tmp_sum < ans_dis:
ans_dis = tmp_sum
ans_town = i
print(str(ans_town) + " " + str(ans_dis)) |
s468059789 | p00189 | u695154284 | 1492095027 | Python | Python3 | py | Runtime Error | 0 | 0 | 1048 | def solve(_dp, _v):
for k in range(0, _v + 1):
for i in range(0, _v + 1):
for j in range(0, _v + 1):
_dp[i][j] = min(_dp[i][j], _dp[i][k] + _dp[k][j])
return _dp
if __name__ == '__main__':
while True:
n = int(input())
if n == 0: break
dp = [[100000] * 10 for i in range(10)]
v = 0
for i in range(0, n):
dp[i][i] = 0
inputs = list(map(int, input().split()))
dp[inputs[0]][inputs[1]] = inputs[2]
dp[inputs[1]][inputs[0]] = inputs[2]
if v < inputs[0]:
v = inputs[0]
if v < inputs[1]:
v = inputs[1]
dp = solve(dp, v)
ans_town = 0
ans_dis = float("inf")
for i in range(0, v + 1):
tmp_sum = 0
for j in range(0, v + 1):
tmp_sum += dp[i][j]
if tmp_sum < ans_dis:
ans_dis = tmp_sum
ans_town = i
print(str(ans_town) + " " + str(ans_dis)) |
s181355653 | p00189 | u798803522 | 1508129533 | Python | Python3 | py | Runtime Error | 0 | 0 | 660 | road = int(input())
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(connect.keys()) + 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1 , float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print(*sum_ans)
road = int(input()) |
s788068710 | p00189 | u798803522 | 1508129572 | Python | Python3 | py | Runtime Error | 0 | 0 | 660 | road = int(input())
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(connect.keys()) + 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1 , float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print(*sum_ans)
road = int(input()) |
s585325258 | p00189 | u798803522 | 1508129639 | Python | Python3 | py | Runtime Error | 0 | 0 | 706 | road = int(input())
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
city = 0
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(city, c1, c2)
city = max(connect.keys()) + 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1 , float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print(*sum_ans)
road = int(input()) |
s616745417 | p00189 | u011621222 | 1509611180 | Python | Python3 | py | Runtime Error | 0 | 0 | 950 | while True:
N = int(input())
if N == 0:
break
INF = 1000000000
mat = []
for i in range(10):
row = []
for j in range(10):
if i == j:
row.append(0)
else:
row.append(INF)
mat.append(row)
for i in range(N):
inputs = input().split()
s = int(inputs[0])
e = int(inputs[1])
r = int(inputs[2])
mat[s][e] = r
mat[e][s] = r
for k in range(N):
for i in range(N):
for j in range(N):
mat[i][j] = min(mat[i][j], mat[i][k] + mat[j][k])
ans_num = 0
ans = INF * 10
for i in range(10):
tmp_ans = 0
for j in mat[i]:
tmp_ans += j
if ans > tmp_ans:
ans_num = i
ans = tmp_ans
ans = 0
for i in mat[ans_num]:
if i != INF:
ans += i
print("%s %s" % (ans_num, ans)) |
s572332414 | p00191 | u408260374 | 1432209154 | Python | Python | py | Runtime Error | 0 | 0 | 664 | from math import sqrt
prime = [1 for _ in xrange(10**6+1)]
prime[1] = 1
prime[0] = 0
for i in xrange(2, int(sqrt(10**6+1))+1):
if prime[i] == 1:
for j in xrange(i+i, 10**6+1, i):
prime[j] = 0
while True:
N, X = map(int, raw_input().split())
if (N, X) == (0, 0): break
price = [input() for _ in xrange(N)]
dp = [0] * (X+1)
dp[0] = 1
for i in xrange(X+1):
if dp[i] == 0: continue
for p in price:
if i + p <= X:
dp[i+p] = 1
for i in xrange(X, -1, -1):
if i > 0 and dp[i] == 1 and prime[i] == 1:
print(i)
break
else:
print("NA") |
s936661746 | p00191 | u847467233 | 1529445629 | Python | Python3 | py | Runtime Error | 0 | 0 | 526 | # AOJ 0191: Baby Tree
# Python3 2018.6.20 bal4u
while True:
n, m = list(map(int, input().split()))
if n == 0: break
d = [[0.0 for j in range(n)] for i in range(n)]
for i in range(n): d[i] = list(map(float, input().split()))
dp = [[0.0 for j in range(n)] for i in range(n)]
for i in range(n): dp[0][i] = 1
for k in range(1, m):
for i in range(n):
for j in range(n):
dp[k][j] = max(dp[k][j], dp[k-1][i]*d[i][j])
ans = 0
for i in range(n):
if dp[m-1][i] > ans: ans = dp[m-1][i]
print(format(ans, ".2f"))
|
s076779886 | p00192 | u352394527 | 1529749517 | Python | Python3 | py | Runtime Error | 0 | 0 | 2007 | from collections import deque
def out(time, parking):
x = len(parking)
outs1 = []
outs2 = []
for i in range(x):
for j in range(2):
if parking[i][j] != None:
parking[i][j][0] -= time
for i in range(x):
c1 = parking[i][0]
c2 = parking[i][1]
if c1 != None and c2 != None:
if c1[0] <= 0 and c2[0] <= 0:
outs1.append(c2[1])
outs2.append(c1[1])
parking[i][0] = None
parking[i][1] = None
elif c2[0] <= 0:
outs1.append(c2[1])
parking[i][1] = None
elif c1 != None:
if c1[0] <= 0:
outs1.append(c1[1])
parking[i][0] = None
elif c2 != None:
if c2[0] <= 0:
outs.append(c2[1])
parking[i][1] = None
outs1.sort()
outs2.sort()
return outs1 + outs2
def into(num, time, parking):
x = len(parking)
times = []
for i in range(x):
if parking[i] == [None, None]:
parking[i][0] = [time, num]
return
if parking[i][0] == None:
times.append((parking[i][1][0], i))
elif parking[i][1] == None:
times.append((parking[i][0][0], i))
times.sort()
for t, ind in times:
if t >= time:
if parking[ind][0] == None:
parking[ind][0] = [time, num]
else:
parking[ind][1] = [time, num]
break
else:
max_t = t
for t, ind in times:
if t == max_t:
if parking[ind][0] == None:
parking[ind][0] = [time, num]
else:
parking[ind][1] = [time, num]
break
while True:
m, n = map(int, input().split())
if m == 0:
break
parking = [[None] * 2 for _ in range(m)]
wait = deque()
space = m * 2
ans = []
for t in range(120 * n):
o = out(1, parking)
if o:
space += len(o)
ans += o
if t % 10 == 0 and t <= 10 * (n - 1):
time = int(input())
wait.append((t // 10 + 1, time))
for i in range(min(space, len(wait))):
num, time = wait.popleft()
into(num, time, parking)
space -= 1
print(*ans)
|
s595043322 | p00193 | u492556875 | 1424364852 | Python | Python3 | py | Runtime Error | 0 | 0 | 1483 | import sys
def generate_next_hexes(x, y):
hexes = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
if y % 2:
hexes += [(x - 1, y - 1), (x - 1, y + 1)]
else:
hexes += [(x + 1, y - 1), (x + 1, y + 1)]
hexes = [(a, b) for (a, b) in hexes if 1 <= b <= m and 1 <= b <= n]
return hexes
def update_map(hex_map, hexes):
num_updated_hexes = 0
distance = 0
while hexes:
next_hexes = []
for pos in hexes:
if pos not in hex_map or distance < hex_map[pos]):
hex_map[pos] = distance
num_updated_hexes += 1
next_hexes += generate_next_hexes(pos[0], pos[1])
distance += 1
hexes = next_hexes
return num_updated_hexes
while True:
(m, n) = [int(i) for i in sys.stdin.readline().split()]
if m == n == 0:
break
s = int(sys.stdin.readline())
stores = []
for i in range(s):
pos = [int(j) for j in sys.stdin.readline().split()]
stores.append(tuple(pos))
hex_map = {}
update_map(hex_map, stores)
t = int(sys.stdin.readline())
candidates = []
for i in range(t):
pos = [int(j) for j in sys.stdin.readline().split()]
candidates.append(tuple(pos))
max_num_blocks = 0
for candidate in candidates:
new_hex_map = hex_map.copy()
num_blocks = update_map(new_hex_map, [candidate])
max_num_blocks = max(max_num_blocks, num_blocks)
print(max_num_blocks) |
s842612108 | p00193 | u647766105 | 1394761351 | Python | Python | py | Runtime Error | 0 | 0 | 1161 | #Deven-Eleven:
D = (((-1, -1), (0, -1), (1, 0), (0, 1), (-1, 1), (-1, 0)),
((0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 0)))
def func(y, x):
q = [(y, x, 0)]
cover = [[-1] * m for _ in xrange(n)]
while len(q) != 0:
y, x, step = q.pop(0)
if cover[y][x] >= 0:
continue
cover[y][x] = step
for dx, dy in D[y % 2]:
ny, nx = y + dy, x + dx
if 0 <= ny < n and 0 <= nx < m:
q.append((ny, nx, step + 1))
return cover
def solve():
scover = [func(pos[1] - 1, pos[0] - 1) for pos in spos]
def count(cover):
ret = 0
for y in xrange(n):
for x in xrange(m):
if cover[y][x] < min(sc[y][x] for sc in scover):
ret += 1
return ret
return max(count(func(pos[1] - 1, pos[0] - 1)) for pos in tpos)
while True:
data = raw_input()
if data == "0":
break
m, n = map(int, data.split())
s = input()
spos = [map(int, raw_input().split()) for _ in xrange(s)]
t = input()
tpos = [map(int, raw_input().split()) for _ in xrange(t)]
print solve() |
s280286225 | p00193 | u647766105 | 1394763561 | Python | Python | py | Runtime Error | 0 | 0 | 1179 | #Deven-Eleven:
D = (((-1, -1), (0, -1), (1, 0), (0, 1), (-1, 1), (-1, 0)),
((0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 0)))
def func(y, x):
q = [(y, x, 0)]
cover = [[-1] * m for _ in xrange(n)]
while len(q) != 0:
y, x, step = q.pop(0)
if cover[y][x] >= 0:
continue
cover[y][x] = step
for dx, dy in D[y % 2]:
ny, nx = y + dy, x + dx
if 0 <= ny < n and 0 <= nx < m and cover[ny][nx] < 0:
q.append((ny, nx, step + 1))
return cover
def solve():
scover = [func(pos[1] - 1, pos[0] - 1) for pos in spos]
def count(cover):
ret = 0
for y in xrange(n):
for x in xrange(m):
if cover[y][x] < min(sc[y][x] for sc in scover):
ret += 1
return ret
return max(count(func(pos[1] - 1, pos[0] - 1)) for pos in tpos)
while True:
data = raw_input()
if data == "0":
break
m, n = map(int, data.split())
s = input()
spos = [map(int, raw_input().split()) for _ in xrange(s)]
t = input()
tpos = [map(int, raw_input().split()) for _ in xrange(t)]
print solve() |
s831656792 | p00193 | u647766105 | 1394763723 | Python | Python | py | Runtime Error | 0 | 0 | 1159 | D = (((-1, -1), (0, -1), (1, 0), (0, 1), (-1, 1), (-1, 0)), ((0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 0)))
def func(y, x):
q = [(y, x, 0)]
cover = [[-1] * m for _ in xrange(n)]
while len(q) != 0:
y, x, step = q.pop(0)
if cover[y][x] >= 0:
continue
cover[y][x] = step
for dx, dy in D[y % 2]:
ny, nx = y + dy, x + dx
if 0 <= ny < n and 0 <= nx < m and cover[ny][nx] < 0:
q.append((ny, nx, step + 1))
return cover
def solve():
scover = [func(pos[1] - 1, pos[0] - 1) for pos in spos]
def count(cover):
ret = 0
for y in xrange(n):
for x in xrange(m):
if cover[y][x] < min(sc[y][x] for sc in scover):
ret += 1
return ret
return max(count(func(pos[1] - 1, pos[0] - 1)) for pos in tpos)
while True:
data = raw_input()
if data == "0":
break
m, n = map(int, data.split())
s = input()
spos = [map(int, raw_input().split()) for _ in xrange(s)]
t = input()
tpos = [map(int, raw_input().split()) for _ in xrange(t)]
print solve() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.