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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s336877881 | p00467 | u889593139 | 1521683910 | Python | Python3 | py | Runtime Error | 0 | 0 | 402 | while True:
N, M = map(int, input().split())
if N == 0:
break
mapp = [int(input()) for _ in range(N)]
mas = 0
ans = 0
for dice in range(M):
mas += int(input())
if mas >= n - 1 and ans == 0:
ans = dice + 1
if mas < n - 1:
lmas += mapp[ans]
if mas >= n - 1 and ans == 0:
ans = dice + 1
print(ans)
|
s295044733 | p00467 | u889593139 | 1521683953 | Python | Python3 | py | Runtime Error | 0 | 0 | 401 | while True:
N, M = map(int, input().split())
if N == 0:
break
maps = [int(input()) for _ in range(N)]
mas = 0
ans = 0
for dice in range(M):
mas += int(input())
if mas >= n - 1 and ans == 0:
ans = dice + 1
if mas < n - 1:
mas += maps[ans]
if mas >= n - 1 and ans == 0:
ans = dice + 1
print(ans)
|
s011631144 | p00467 | u150984829 | 1526187315 | Python | Python3 | py | Runtime Error | 0 | 0 | 202 | for e in iter(input,'0 0'):
N,M=map(int,e.split())
S=[int(input())for _ in[0]*N]
print(S)
p=b=1
for i in range(M):
d=int(input())
p+=d
p+=S[~-p]
print('pos', p)
if(N<=p)*b:print(-~i);b=0
|
s944684798 | p00467 | u150984829 | 1526187326 | Python | Python3 | py | Runtime Error | 0 | 0 | 184 | for e in iter(input,'0 0'):
N,M=map(int,e.split())
S=[int(input())for _ in[0]*N]
print(S)
p=b=1
for i in range(M):
d=int(input())
p+=d
p+=S[~-p]
if(N<=p)*b:print(-~i);b=0
|
s985961919 | p00467 | u150984829 | 1526187369 | Python | Python3 | py | Runtime Error | 0 | 0 | 174 | for e in iter(input,'0 0'):
N,M=map(int,e.split())
S=[int(input())for _ in[0]*N]
p=b=1
for i in range(M):
d=int(input())
p+=d
p+=S[~-p]
if(N<=p)*b:print(-~i);b=0
|
s068721091 | p00467 | u150984829 | 1526187885 | Python | Python3 | py | Runtime Error | 0 | 0 | 195 | for e in iter(input,'0 0'):
N,M=map(int,e.split())
k=p=1
S=[int(input()) for _ in[0]*N]
for d in[int(input())for _ in[0]*M]:
p+=n if n-1<=p+i else i+S[p+i]
if n<=p:break
k+=1
print(k)
|
s978964313 | p00467 | u150984829 | 1526188276 | Python | Python3 | py | Runtime Error | 0 | 0 | 196 | for e in iter(input,'0 0'):
N,M=map(int,e.split())
k,p=1,0
S=[int(input()) for _ in[0]*N]
for d in[int(input())for _ in[0]*M]:
p+=d if N<p+d else d+S[p+d]
if N<=p+1:break
k+=1
print(k)
|
s361236576 | p00467 | u150984829 | 1526188687 | Python | Python3 | py | Runtime Error | 0 | 0 | 266 | import sys
r=sys.stdin.readline
def s():
for e in iter(r,'0 0'):
N,M=map(int,e.split())
k,p=1,0
S=[int(r()) for _ in[0]*N]
for d in[int(r())for _ in[0]*M]:
p+=d if N<=p+d else d+S[p+d]
if N<=p+1:break
k+=1
print(k)
if'__main__'==__name__:solve()
|
s845199903 | p00467 | u150984829 | 1526188701 | Python | Python3 | py | Runtime Error | 0 | 0 | 262 | import sys
r=sys.stdin.readline
def s():
for e in iter(r,'0 0'):
N,M=map(int,e.split())
k,p=1,0
S=[int(r()) for _ in[0]*N]
for d in[int(r())for _ in[0]*M]:
p+=d if N<=p+d else d+S[p+d]
if N<=p+1:break
k+=1
print(k)
if'__main__'==__name__:s()
|
s488027919 | p00467 | u150984829 | 1526188779 | Python | Python3 | py | Runtime Error | 0 | 0 | 264 | def s():
import sys
r=sys.stdin.readline
for e in iter(r,'0 0'):
N,M=map(int,e.split())
k,p=1,0
S=[int(r()) for _ in[0]*N]
for d in[int(r())for _ in[0]*M]:
p+=d if N<=p+d else d+S[p+d]
if N<=p+1:break
k+=1
print(k)
if'__main__'==__name__:s()
|
s022114148 | p00467 | u150984829 | 1526189157 | Python | Python3 | py | Runtime Error | 0 | 0 | 214 | import sys
r=sys.stdin.readline
for e in iter(r,'0 0\n'):
N,M=map(int,e.split())
k,p=1,0
S=[int(r()) for _ in[0]*N]
for d in[int(r())for _ in[0]*M]:
p+=d;
if N<=p:p+=S[p]
if N<=p+1:break
k+=1
print(k)
|
s506539798 | p00467 | u621997536 | 1384424492 | Python | Python | py | Runtime Error | 0 | 0 | 317 | mass = [0] * 1000
num = [0] * 1000
while True:
N, M = map(int, raw_input().split())
if N == 0 and M == 0:
break
p = 0
for i in range(N):
mass[i] = input()
for i in range(M):
num[i] = input()
for i in range(M):
p += num[i];
p += mass[p]
if p >= N - 1:
print i + 1
break |
s491459033 | p00467 | u260980560 | 1397474879 | Python | Python | py | Runtime Error | 0 | 0 | 310 | while True:
n, m = map(int, raw_input().split())
if n==0 and m==0:
break
b = [input() for i in xrange(n)]
p = 0; ans = 0;
for i in xrange(m):
d = input()
p += d
if p>=n-1 or p+b[p]>=n-1:
ans = i+1
break
p += b[p]
print ans |
s869343561 | p00468 | u724963150 | 1507199114 | Python | Python3 | py | Runtime Error | 0 | 0 | 403 | while True:
n=int(input())
if n==0:break
m=int(input())
rel=sorted([[int(s)for s in input().split(" ")]for i in range(m)],key=lambda x:x[0])
isf=[False for i in range(n)]
inv=[False for i in range(n)]
isf[0]=True
for r in rel:
if r[0]==1:
isf[r[1]]=True
inv[r[1]]=True
elif isf[r[0]]==True:inv[r[1]]=True
print(inv.count(True)) |
s742444896 | p00468 | u150984829 | 1526191342 | Python | Python3 | py | Runtime Error | 0 | 0 | 208 | import sys
r=sys.stdin.readline
for e in iter(r,'0'):
R=[[]for _ in[0]*-~int(e)]
for _ in[0]*int(r()):
a,b=map(int,r().split())
R[a]+=[b];R[b]+=[a]
for m in R[1][:]:R[1]+=R[m]
print(len({*R[1]}-{1}))
|
s090396055 | p00468 | u460331583 | 1347008862 | Python | Python | py | Runtime Error | 0 | 1544 | 402 | while True:
fri = int(input())
count = int(input())
if fri == 0 and count ==0: break
a,b,c,d = [],[],[],[]
for i in range(count):
t = map(int,raw_input().split())
if t[0] == 1:
if not(t[1] in b):
b.append(t[1])
continue
if t[0] in b:
if not(t[1] in b):
c.append(t[1])
continue
else: continue
g = int(len(b))+int(len(c))
print g |
s417929578 | p00468 | u104911888 | 1368797798 | Python | Python | py | Runtime Error | 0 | 0 | 362 | while True:
n,m=input(),input()
if n==m==0:break
S,L=set(),[]
for i in range(m):
a,b=map(int,raw_input().split())
if a==1:
S.add(b)
elif b==1:
S.add(a)
else:
L.append((a,b))
for i in S:
for s in L:
if i in s:
S=S.union(s)
print len(S) |
s982235680 | p00468 | u104911888 | 1368797850 | Python | Python | py | Runtime Error | 0 | 0 | 366 | while True:
n=input()
m=input()
if n==m==0:break
S,L=set(),[]
for i in range(m):
a,b=map(int,raw_input().split())
if a==1:
S.add(b)
elif b==1:
S.add(a)
else:
L.append((a,b))
for i in S:
for s in L:
if i in s:
S=S.union(s)
print len(S) |
s433924265 | p00468 | u104911888 | 1368797916 | Python | Python | py | Runtime Error | 0 | 0 | 420 | while True:
try:
n=input()
m=input()
except SyntaxError:
pass
if n==m==0:break
S,L=set(),[]
for i in range(m):
a,b=map(int,raw_input().split())
if a==1:
S.add(b)
elif b==1:
S.add(a)
else:
L.append((a,b))
for i in S:
for s in L:
if i in s:
S=S.union(s)
print len(S) |
s516596459 | p00468 | u104911888 | 1368797985 | Python | Python | py | Runtime Error | 0 | 0 | 375 | while True:
n,m=map(int,raw_input().split())
if n==m==0:break
S,L=set(),[]
for i in range(m):
a,b=map(int,raw_input().split())
if a==1:
S.add(b)
elif b==1:
S.add(a)
else:
L.append((a,b))
for i in S:
for s in L:
if i in s:
S=S.union(s)
print len(S) |
s467536185 | p00468 | u104911888 | 1368798030 | Python | Python | py | Runtime Error | 0 | 0 | 384 | while True:
n=int(raw_input())
m=int(raw_input())
if n==m==0:break
S,L=set(),[]
for i in range(m):
a,b=map(int,raw_input().split())
if a==1:
S.add(b)
elif b==1:
S.add(a)
else:
L.append((a,b))
for i in S:
for s in L:
if i in s:
S=S.union(s)
print len(S) |
s021741665 | p00468 | u104911888 | 1368798817 | Python | Python | py | Runtime Error | 0 | 0 | 363 | while True:
n=input()
m=input()
if n==0:break
S,L=set(),[]
for i in range(m):
a,b=map(int,raw_input().split())
if a==1:
S.add(b)
elif b==1:
S.add(a)
else:
L.append((a,b))
for i in S:
for s in L:
if i in s:
S=S.union(s)
print len(S) |
s850038616 | p00468 | u104911888 | 1368798908 | Python | Python | py | Runtime Error | 0 | 0 | 371 | while True:
n=raw_input()
m=input()
if n in "0":break
S,L=set(),[]
for i in range(m):
a,b=map(int,raw_input().split())
if a==1:
S.add(b)
elif b==1:
S.add(a)
else:
L.append((a,b))
for i in S:
for s in L:
if i in s:
S=S.union(s)
print len(S) |
s112907486 | p00468 | u104911888 | 1368798940 | Python | Python | py | Runtime Error | 0 | 0 | 371 | while True:
n=raw_input()
if n in "0":break
m=input()
S,L=set(),[]
for i in range(m):
a,b=map(int,raw_input().split())
if a==1:
S.add(b)
elif b==1:
S.add(a)
else:
L.append((a,b))
for i in S:
for s in L:
if i in s:
S=S.union(s)
print len(S) |
s697823074 | p00468 | u621997536 | 1384425839 | Python | Python | py | Runtime Error | 0 | 0 | 574 | l = []
t = []
ans = [False] * 500
while True:
l = []
t = []
ans = [False] * 500
N = input()
M = input()
if N == 0 and M == 0:
break
for i in range(M):
a, b = map(int, raw_input().split())
l.append([a, b])
if a == 1:
t.append(b)
if b == 1:
t.append(a)
for i in t:
ans[i] = True
for j in range(M):
if l[j][0] == i:
ans[l[j][1]] = True
if l[j][1] == i:
ans[l[j][0]] = True
res = 0
for i in range(len(ans)):
if ans[i] and i != 1:
print "tes: %d" % (i)
res += 1
print res |
s841077819 | p00469 | u150984829 | 1526193473 | Python | Python3 | py | Runtime Error | 0 | 0 | 181 | from itertools import permutations as P
import sys
r=sys.stdin.readline
for e in iter(r,'0'):
n,k=int(e),int(r())
C=[r()for _ in[0]*n]
print(len(set(''.join(s)for s in P(C,k))))
|
s642827987 | p00469 | u759949288 | 1361356162 | Python | Python | py | Runtime Error | 0 | 0 | 208 | from itertools import permutations
while True:
n = input()
if n == 0: break
k = input()
nums = [raw_input() for i in xrange(n)]
result = set("".join(p) for p in permutations(nums, k))
print len(result) |
s501333884 | p00469 | u759949288 | 1361356223 | Python | Python | py | Runtime Error | 0 | 0 | 213 | from itertools import permutations
while True:
n = input()
k = input()
if n == k == 0: break
nums = [raw_input() for i in xrange(n)]
result = set("".join(p) for p in permutations(nums, k))
print len(result) |
s317281631 | p00469 | u759949288 | 1361356925 | Python | Python | py | Runtime Error | 0 | 0 | 255 | from itertools import permutations
while True:
n = int(raw_input().strip())
k = int(raw_input().strip())
if n == k == 0: break
nums = [raw_input().strip() for i in xrange(n)]
result = set("".join(p) for p in permutations(nums, k))
print len(result) |
s386329876 | p00469 | u759949288 | 1361357001 | Python | Python | py | Runtime Error | 0 | 0 | 259 | from itertools import permutations
while True:
n = int(raw_input().strip())
k = int(raw_input().strip())
if n == k == 0:
break
nums = [raw_input().strip() for i in xrange(n)]
result = set(["".join(p) for p in permutations(nums, k)])
print len(result) |
s435834863 | p00469 | u759949288 | 1361357090 | Python | Python | py | Runtime Error | 0 | 0 | 154 | while True:
n = int(raw_input().strip())
k = int(raw_input().strip())
if n == k == 0:
break
nums = [raw_input().strip() for i in xrange(n)]
print 0 |
s796362694 | p00469 | u759949288 | 1361357301 | Python | Python | py | Runtime Error | 0 | 0 | 226 | from itertools import permutations
while True:
n = input()
k = input()
if n == k == 0:
break
nums = [raw_input().strip() for i in xrange(n)]
result = set(["".join(p) for p in permutations(nums, k)])
print(len(result)) |
s978886653 | p00469 | u759949288 | 1361357363 | Python | Python | py | Runtime Error | 0 | 0 | 243 | import sys
from itertools import permutations
while True:
n = input()
k = input()
if n == k == 0:
sys.exit(0)
nums = [raw_input().strip() for i in xrange(n)]
result = set(["".join(p) for p in permutations(nums, k)])
print(len(result)) |
s087184729 | p00469 | u759949288 | 1361357450 | Python | Python | py | Runtime Error | 0 | 0 | 307 | import sys
from itertools import permutations
def main():
while True:
n = input()
k = input()
if n == k == 0:
return 0
nums = [raw_input().strip() for i in xrange(n)]
result = set(["".join(p) for p in permutations(nums, k)])
print (len(result))
if __name__ == '__main__':
sys.exit(main()) |
s218009346 | p00469 | u759949288 | 1361357894 | Python | Python | py | Runtime Error | 0 | 0 | 321 | import sys
from itertools import permutations
def main():
while True:
n, k = map(int, raw_input().split())
if n == k == 0:
sys.exit(0)
nums = [raw_input().strip() for i in xrange(n)]
result = set(["".join(p) for p in permutations(nums, k)])
print (len(result))
if __name__ == '__main__':
sys.exit(main()) |
s611252533 | p00469 | u759949288 | 1361359865 | Python | Python | py | Runtime Error | 0 | 0 | 346 | import sys
from itertools import permutations
def main():
while True:
n = input()
k = input()
if n == k == 0:
sys.exit(0)
for i in xrange(n):
input()
# nums = [raw_input().strip() for i in xrange(n)]
# result = set(["".join(p) for p in permutations(nums, k)])
# print (len(result))
if __name__ == '__main__':
sys.exit(main()) |
s987634106 | p00469 | u104911888 | 1368799453 | Python | Python | py | Runtime Error | 0 | 0 | 212 | import itertools
while True:
n=input()
k=input()
if n==k==0:break
L=[raw_input() for i in range(n)]
S=set()
for t in itertools.permutations(L,k):
S.add("".join(t))
print len(S) |
s496589464 | p00469 | u104911888 | 1368799596 | Python | Python | py | Runtime Error | 0 | 0 | 273 | import itertools
while True:
n=raw_input()
if n in "0":break
try:
k=input()
except SyntaxError:
break
L=[raw_input() for i in range(int(n))]
S=set()
for t in itertools.permutations(L,k):
S.add("".join(t))
print len(S) |
s331159036 | p00470 | u150984829 | 1526200076 | Python | Python3 | py | Runtime Error | 0 | 0 | 262 | for e in iter(input,'0 0'):
w,h=map(int,e.split())
M=[[[1,0]*2 for _ in[0]*h]for _ in[0]*w]
for i in range(1,w):
for j in range(1,h):
a=M[i-1][j][:2]
b=M[i][j-1][2:]
M[i][j]=[b[1],a,a[1],b]
print((sum(M[w-2][h-1][:2])+sum(M[w-1][h-2][2:]))%10**5)
|
s643025090 | p00470 | u759949288 | 1361357766 | Python | Python | py | Runtime Error | 0 | 0 | 355 | import sys
from itertools import permutations
def main():
while True:
n = input()
k = input()
if n == k == 0:
return 0
for i in xrange(n):
input()
print "a"
# nums = [raw_input().strip() for i in xrange(n)]
# result = set(["".join(p) for p in permutations(nums, k)])
# print (len(result))
if __name__ == '__main__':
sys.exit(main()) |
s816986110 | p00471 | u797673668 | 1457700748 | Python | Python3 | py | Runtime Error | 40000 | 7868 | 1865 | def search(town, remains, i, j):
if not remains:
if i == church[0]:
direction = 1 if j < church[1] else -1
for cj in range(j + direction, church[1], direction):
if town[i][cj] == 3:
return 0
return 1
elif j == church[1]:
direction = 1 if i < church[0] else -1
for ci in range(i + direction, church[0], direction):
if town[ci][j] == 3:
return 0
return 1
return 0
counter = 0
for ci in range(i - 1, -1, -1):
if town[ci][j] == 1:
town[ci][j] = 3
counter += search(town, remains - 1, ci, j)
town[ci][j] = 1
elif town[ci][j] == 3:
break
for ci in range(i + 1, n):
if town[ci][j] == 1:
town[ci][j] = 3
counter += search(town, remains - 1, ci, j)
town[ci][j] = 1
elif town[ci][j] == 3:
break
for cj in range(j - 1, -1, -1):
if town[i][cj] == 1:
town[i][cj] = 3
counter += search(town, remains - 1, i, cj)
town[i][cj] = 1
elif town[i][cj] == 3:
break
for cj in range(j + 1, m):
if town[i][cj] == 1:
town[i][cj] = 3
counter += search(town, remains - 1, i, cj)
town[i][cj] = 1
elif town[i][cj] == 3:
break
return counter
while True:
m, n = map(int, input().split())
if not n:
break
town = [list(map(int, input().split())) for _ in range(n)]
remains = 0
for i in range(n):
for j in range(m):
house = town[i][j]
if house == 2:
church = (i, j)
elif house == 1:
remains += 1
print(search(town, remains, *church)) |
s435323488 | p00471 | u150984829 | 1526211381 | Python | Python3 | py | Runtime Error | 0 | 0 | 3380 | '''
今年も JOI 町にサンタクロースが空からやってきた.JOI 町にある全ての家には子供がいるので,この
サンタクロースは JOI 町の全ての家にプレゼントを配ってまわらなければならない.しかし,今年は連れ
ているトナカイが少々方向音痴であり,また建物の上以外に降りることができないため,全ての家にプレゼ
ントを配るためには少々道順を工夫しなければならないようだ.
JOI 町は東西南北に区画整理されており,各区画は家,教会,空き地のいずれかである.JOI 町には 1
つだけ教会がある.次のルールに従い,サンタクロースとトナカイは教会から出発し,全ての家に 1 回ず
つプレゼントを配った後,教会に戻る.
- 今年のトナカイは少々方向音痴であるため,東西南北いずれかの方向にまっすぐ飛ぶことしかできず,空
中では方向転換できない.
- まだプレゼントを配っていない家の上は自由に通過できる.まだプレゼントを配っていない家には降りる
ことができる.家に降りた時は必ずプレゼントを配り,その後は東西南北いずれかの方向に飛び立つ.
- JOI 町の家では,クリスマスの夜はサンタクロースが来るまでは暖炉をつけずに過ごしているが,サン
タクロースが飛び立った後は暖炉をつける.暖炉をつけると煙突から煙が出るので,プレゼントを配り終
えた家の上を通過することはできない.
- 教会の上は自由に通過することができる.しかし,教会では礼拝が行われているので,全てのプレゼント
を配り終えるまで教会に降りることはできない.
- 空き地の上は自由に通過することができるが,空き地に降りることはできない.
入力として町の構造が与えられたとき,サンタクロースとトナカイがプレゼントを配る道順が何通りあるか
を求めるプログラムを作成せよ.
'''
import copy
dc = copy.deepcopy
ans = 0
M = N = 0
def walk(field, pos_x, pos_y, direction):
now_state = field[pos_y][pos_x]
if now_state == 2:
if sum(sum(field, [])) == 2:
global ans
ans += 1
return
field[pos_y][pos_x] = 0
if (now_state or direction == 'r') and pos_x < M - 1:
walk(dc(field), pos_x + 1, pos_y, 'r')
if (now_state or direction == 'l') and 0 < pos_x:
walk(dc(field), pos_x - 1, pos_y, 'l')
if (now_state or direction == 'u') and 0 < pos_y:
walk(dc(field), pos_x, pos_y - 1, 'u')
if (now_state or direction == 'd') and pos_y < N - 1:
walk(dc(field), pos_x, pos_y + 1, 'd')
for e in iter(input, '0 0'):
M, N = map(int, e.split())
field = []
for i in range(N):
row = list(map(int, input().split()))
field.append(row)
if 2 in row:
ch_x = row.index(2)
ch_y = i
if ch_x < M - 1:
walk(dc(field), ch_x + 1, ch_y, 'r')
if 0 < ch_x:
walk(dc(field), ch_x - 1, ch_y, 'l')
if 0 < ch_y:
walk(dc(field), ch_x, ch_y - 1, 'u')
if ch_y < N - 1:
walk(dc(field), ch_x, ch_y + 1, 'd')
print(ans)
|
s093633991 | p00472 | u811434779 | 1443166057 | Python | Python | py | Runtime Error | 40000 | 16632 | 353 | DIV = 100000
n, m = map(int, raw_input().split())
l = [input() for _ in range(n-1)]
ans = [0]*(n-1)
pos = 0
for _ in range(m):
k = input()
if k > 0:
for i in range(k): ans[pos+i] += 1
else:
for i in range(-1, k-1, -1):
ans[pos+i] += 1
pos += k
print sum((ans[i] * l[i]) % DIV for i in range(n-1)) % DIV |
s242030032 | p00472 | u811434779 | 1443166493 | Python | Python | py | Runtime Error | 40000 | 10332 | 357 | DIV = 100000
n, m = map(int, raw_input().split())
l = [input() for _ in range(n-1)]
ans = [0]*(n-1)
pos = 0
for _ in xrange(m):
k = input()
if k > 0:
for i in xrange(k): ans[pos+i] += 1
else:
for i in xrange(-1, k-1, -1):
ans[pos+i] += 1
pos += k
print sum((ans[i] * l[i]) % DIV for i in xrange(n-1)) % DIV |
s710768916 | p00472 | u901080241 | 1496288042 | Python | Python3 | py | Runtime Error | 40000 | 9064 | 235 | n,m = map(int,input().split())
lng = []
for _ in range(n-1):
lng.append(int(input()))
i = 0
sm = 0
for _ in range(m):
j = i+int(input())
mv = sum(lng[i:j]) if j > i else sum(lng[j:i])
sm += mv
i = j
print(sm%100000) |
s754859966 | p00472 | u901080241 | 1496288224 | Python | Python3 | py | Runtime Error | 40000 | 9004 | 262 | n,m = map(int,input().split())
lng = []
for _ in range(n-1):
lng.append(int(input()))
i = 0
sm = 0
for _ in range(m):
j = i+int(input())
mv = sum(lng[i:j]) if j > i else sum(lng[j:i])
sm += mv
if sm >= 100000: sm -= 100000
i = j
print(sm) |
s347679962 | p00472 | u901080241 | 1496288598 | Python | Python3 | py | Runtime Error | 40000 | 9116 | 245 | n,m = map(int,input().split())
lng = []
for _ in range(n-1):
lng.append(int(input()))
i = 0
sm = 0
for _ in range(m):
j = i+int(input())
mv = sum(lng[i:j]) if j > i else sum(lng[j:i])
sm += mv
sm %= 100000
i = j
print(sm) |
s049881904 | p00472 | u011621222 | 1510225809 | Python | Python3 | py | Runtime Error | 0 | 0 | 1441 | # -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""
#
# Author: Noname
# URL: https://github.com/pettan0818
# License: MIT License
# Created: 木 11/ 9 19:01:14 2017
# Usage
#
"""
from itertools import accumulate
def data_req():
n_yado, m_ryotei = [int(i) for i in input().split(" ")]
yado_distance = []
ryotei = []
for _ in range(n_yado):
yado_distance.append(int(input()))
for _ in range(m_ryotei):
ryotei.append(int(input()))
return yado_distance, ryotei
def search(distance, ryotei):
"""search.
>>> search([2, 1, 1, 3, 2, 1], [2, -1, 3, 2, -3])
18
"""
acc = [0] + list(accumulate(distance, lambda x, y: x+y))
ryotei_index = [0] + list(accumulate(ryotei, lambda x, y: x+y))
# print(ryotei_index)
res = []
for index in enumerate(ryotei_index):
if index[0] == 0:
continue
index = index[0]
# print(index)
# print(ryotei_index[index])
# print(ryotei_index[index - 1])
dist = abs(acc[ryotei_index[index]] - acc[ryotei_index[index - 1]])
res.append(dist)
# print(sum(res))
# his = []
#
# for index in range(len(ryotei_index)):
# his.append(acc[ryotei_index[index + 1]] - acc[ryotei_index[index]])
#
# return sum(his)
return sum(res)
if __name__ == '__main__':
dis, ryotei = data_req()
search(dis, ryotei) |
s539627994 | p00472 | u794549850 | 1391777407 | Python | Python | py | Runtime Error | 0 | 0 | 641 | #include <stdio.h>
int main() {
int i;
int n, m, now_pos, sum;
int s[100000];
int imos[100000];
scanf("%d %d", &n, &m);
for (i=0;i<n-1;i++) {
scanf("%d", &s[i]);
}
now_pos = 0;
for (i=0;i<m;i++) {
int a;
scanf("%d", &a);
if (a < 0) {
imos[now_pos] -= 1;
imos[now_pos+a] += 1;
} else {
imos[now_pos] += 1;
imos[now_pos+a] -= 1;
}
now_pos += a;
}
sum = imos[0] * s[0];
for (i=1;i<n;i++) {
imos[i] += imos[i-1];
sum += imos[i] * s[i];
}
printf("%d\n", sum);
} |
s690409910 | p00473 | u621997536 | 1425296611 | Python | Python3 | py | Runtime Error | 19920 | 6708 | 18 | while True:
pass |
s048464451 | p00473 | u811434779 | 1444998291 | Python | Python | py | Runtime Error | 40000 | 8480 | 267 | n = input()
l = [input() for i in range(n-1)]
dp = [[n*n]*2 for i in range(n+1)]
dp[1][0] = 0
for i in range(1,n):
for j in range(i+1,0,-1):
dp[j][1] = min(dp[j][1], dp[j][0]+l[i-1])
dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i-1])
print min(dp[n/2]) |
s786028238 | p00473 | u811434779 | 1444998655 | Python | Python | py | Runtime Error | 40000 | 8508 | 279 | INF = 1<<31
n = input()
l = [input() for i in range(n-1)]
dp = [[INF]*2 for i in range(n+1)]
dp[1][0] = 0
for i in range(1,n):
for j in range(i+1,0,-1):
dp[j][1] = min(dp[j][1], dp[j][0]+l[i-1])
dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i-1])
print min(dp[n/2]) |
s268814968 | p00473 | u811434779 | 1445004338 | Python | Python | py | Runtime Error | 40000 | 7844 | 283 | INF = 1<<31
n = input()
l = [input() for i in xrange(n-1)]
dp = [[INF]*2 for i in xrange(n+1)]
dp[1][0] = 0
for i in xrange(1,n):
for j in xrange(i+1,0,-1):
dp[j][1] = min(dp[j][1], dp[j][0]+l[i-1])
dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i-1])
print min(dp[n/2]) |
s379004160 | p00473 | u811434779 | 1445004695 | Python | Python | py | Runtime Error | 40000 | 7884 | 299 | INF = 1<<31
n = input()
l = [0]*(n+1)
for i in xrange(1,n):
l[i] = input()
dp = [[INF]*2 for i in xrange(n+1)]
dp[1][0] = 0
for i in xrange(1,n):
for j in xrange(i+1,0,-1):
dp[j][1] = min(dp[j][1], dp[j][0]+l[i])
dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i])
print min(dp[n/2]) |
s751708361 | p00473 | u078042885 | 1485161261 | Python | Python3 | py | Runtime Error | 40000 | 7972 | 188 | dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n):
a=int(input())
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2]) |
s383823053 | p00473 | u078042885 | 1485162354 | Python | Python3 | py | Runtime Error | 0 | 0 | 190 | dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n+1):
a=int(input())
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2]) |
s525745808 | p00473 | u078042885 | 1485163079 | Python | Python3 | py | Runtime Error | 40000 | 8008 | 209 | dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n):
try:a=int(input())
except:break
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2]) |
s901927841 | p00473 | u078042885 | 1485163922 | Python | Python3 | py | Runtime Error | 40000 | 8048 | 211 | dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n+1):
try:a=int(input())
except:break
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2]) |
s876130401 | p00473 | u078042885 | 1485165587 | Python | Python3 | py | Runtime Error | 40000 | 8688 | 234 | import sys
dp=[0]+[1<<20]*10000
n=int(input())
a=list(map(int,sys.stdin.readlines()))
for i in range(1,len(a)):
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a[i-1]),(dp[i-j],dp[j]+a[i-1])])
print(dp[n//2]) |
s377828182 | p00473 | u078042885 | 1485166106 | Python | Python3 | py | Runtime Error | 40000 | 8712 | 229 | import sys
dp=[0]+[1<<20]*10000
n=int(input())
a=list(map(int,sys.stdin.readlines()))
for i in range(1,n):
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a[i-1]),(dp[i-j],dp[j]+a[i-1])])
print(dp[n//2]) |
s762863200 | p00473 | u078042885 | 1485168631 | Python | Python3 | py | Runtime Error | 40000 | 8632 | 337 | #???????????±???????????\????????°????????£?????????????
import sys
dp = [0] + [1 << 20] * 10000
n = int(input())
a = list(map(int, sys.stdin.readlines()))
if len(a)==n:a.pop()
for i in range(1, n) :
for j in range(i//2+1):
dp[j], dp[i - j] = map(min, [(dp[j], dp[i - j] + a[i - 1]), (dp[i - j], dp[j] + a[i - 1])])
print(dp[n//2]) |
s342568110 | p00473 | u078042885 | 1485171099 | Python | Python3 | py | Runtime Error | 40000 | 8064 | 225 | dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n):
a=int(input())
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2])
try:raise RuntimeError
except:exit() |
s885014037 | p00473 | u078042885 | 1485172496 | Python | Python3 | py | Runtime Error | 40000 | 8048 | 195 | dp=[0]+[1<<20]*10000
n=int(input())
for i in range(1,n):
a=int(input())
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2])
exit() |
s742683095 | p00473 | u078042885 | 1485199651 | Python | Python3 | py | Runtime Error | 40000 | 7944 | 221 | dp=[0]+[1<<20]*10000
n=int(input())
c=0
for i in range(1,n):
if c==n-1:break
a=int(input())
c+=1
for j in range(i//2+1):
dp[j],dp[i-j]=map(min,[(dp[j],dp[i-j]+a),(dp[i-j],dp[j]+a)])
print(dp[n//2]) |
s601057742 | p00473 | u901080241 | 1496295240 | Python | Python3 | py | Runtime Error | 40000 | 7760 | 233 | n = int(input())
dp = [float('inf')]*(n+1)
dp[0] = 0
for i in range(1,n):
cost = int(input())
for j in range(i):
dp[j] = min(dp[j],dp[i-j]+cost)
dp[i-j] = min(dp[j]+cost,dp[i-j])
#print(dp)
print(dp[n//2]) |
s601773147 | p00473 | u352394527 | 1525788288 | Python | Python3 | py | Runtime Error | 17490 | 5976 | 733 | INF = 100
n = int(input())
l = [0 if i == 0 else int(input()) for i in range(n)]
#dp = [[[INF] * 2 for i in range(n // 2 + 1)] for j in range(n + 1)]
#
#dp[1][1][0] = 0
#dp[1][0][1] = 0
#
#for i in range(2,n + 1):
# for j in range(1,n // 2 + 1):
# dp[i][j][0] = min(dp[i - 1][j - 1][0], dp[i - 1][j - 1][1] + l[i - 1])
# dp[i][j][1] = min(dp[i - 1][j][1], dp[i - 1][j][0] + l[i - 1])
#print(min(dp[n][n//2][0], dp[n][n//2][1]))
#
dp = [[INF] * 2 for i in range(n // 2 + 1)]
dp[1][0] = 0
dp[0][1] = 0
for i in range(2, n + 1):
for j in range(n // 2, -1, -1):
a = min(dp[j - 1][0], dp[j - 1][1] + l[i - 1])
b = min(dp[j][1], dp[j][0] + l[i - 1])
dp[j][0] = a
dp[j][1] = b
print(max(dp[n//2][0], dp[n//2][1]))
|
s446184621 | p00474 | u266872031 | 1448045150 | Python | Python | py | Runtime Error | 40000 | 12936 | 861 | [N,L]=[int(x) for x in raw_input().split()]
icelist=[0]
for i in range(N):
icelist.append(int(raw_input()))
icelist.append(0)
incindex=[]
for i in range(1,N+1):
if icelist[i]>icelist[i-1] and icelist[i]>icelist[i+1]:
incindex.append(i)
ans=0
popped=0
while popped<N:
addindex=[]
delindex=[]
t=L-max([icelist[i] for i in incindex])
ans+=t
for ii in incindex:
icelist[ii]+=t
if icelist[ii]==L:
popped+=1
delindex.append(ii)
icelist[ii]=0
if ii-1>0:
if icelist[ii-1]>icelist[ii-2]:
addindex.append(ii-1)
if ii+1<N+1:
if icelist[ii+1]>icelist[ii+2]:
addindex.append(ii+1)
for k in delindex:
incindex.remove(k)
for j in addindex:
incindex.append(j)
print ans |
s761719295 | p00474 | u894114233 | 1470732389 | Python | Python | py | Runtime Error | 40000 | 11216 | 369 | n,l=map(int,raw_input().split())
a=[0]+[int(raw_input()) for _ in xrange(n)]+[0]
cnt=0
while a!=[0]*(n+2):
t_id=[]
max_t=-1
for i in xrange(1,n+1):
if a[i-1]<a[i] and a[i]>a[i+1]:
t_id.append(i)
if max_t<a[i]:
max_t=a[i]
cnt+=l-max_t
for i in t_id:
a[i]+=l-max_t
a[i]=a[i]%l
print(cnt) |
s325073194 | p00474 | u894114233 | 1474977331 | Python | Python | py | Runtime Error | 40000 | 12912 | 609 | n,l=map(int,raw_input().split())
a=[0]+[int(raw_input()) for _ in xrange(n)]+[0]
r=[0]*(n+2)
for i in xrange(1,n+1):
if a[i-1]<a[i] and a[i]>a[i+1]:
r[i]=0
elif a[i-1]<a[i] and a[i]<a[i+1]:
r[i]=1
elif a[i-1]>a[i] and a[i]>a[i+1]:
r[i]=1
else:
r[i]=2
time=[0]*(n+2)
while r!=[-1]*(n+2):
for i in xrange(1,n+1):
if r[i]==0:
r[i]=-1
time[i]+=l-a[i]
time[i-1]=max(time[i-1],time[i])
time[i+1]=max(time[i+1],time[i])
if r[i-1]!=-1:r[i-1]-=1
if r[i+1]!=-1:r[i+1]-=1
print(max(time)) |
s244480462 | p00474 | u894114233 | 1474978906 | Python | Python | py | Runtime Error | 40000 | 11064 | 379 | n,l=map(int,raw_input().split())
a=[0]+[int(raw_input()) for _ in xrange(n)]+[0]
ti=[0]*(n+2)
while a!=[0]*(n+2):
for i in xrange(1,n+1):
if a[i-1]<a[i] and a[i]>a[i+1]:
ti[i]+=l-a[i]
a[i]=0
if a[i-1]!=0:
ti[i-1]=max(ti[i-1],ti[i])
if a[i+1]!=0:
ti[i+1]=max(ti[i+1],ti[i])
print(max(ti)) |
s339179497 | p00474 | u198881450 | 1497439268 | Python | Python3 | py | Runtime Error | 0 | 0 | 865 | def greedy(N,L,ices):
counts = 0
while True:
for i in range(len(ices)):
if 0 < i < N-1:
if ices[i] > ices[i-1] and ices[i] > ices[i+1]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
elif i == 0:
if ices[i] > ices[1]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
elif i == N-1:
if ices[i] > ices[N-2]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
if ices.count(0) == N:
print(counts)
return
counts += 1
N,L = input().rstrip().split()
ices = []
while True:
ice = input().rstrip()
ices.append(ice)
if len(ices) == N:
break
greedy(N,L,ices) |
s921684860 | p00474 | u945345165 | 1497439437 | Python | Python3 | py | Runtime Error | 40000 | 19460 | 766 | def update(arr, diff):
neoArr = []
for i in range(len(arr)):
tmp = 0
if i==0:
if arr[i]>arr[i+1]:
tmp = diff
elif i==len(arr)-1:
if arr[i]>arr[i-1]:
tmp = diff
else:
if arr[i]>arr[i-1] and arr[i]>arr[i+1]:
tmp = diff
neoArr.append(arr[i] + tmp)
if neoArr[i] == L:
neoArr[i] = 0
return neoArr
def solve(arr):
count = 0
while True:
maxInt = max(arr)
if maxInt == 0:
break
diff = L-maxInt
arr = update(arr,diff)
count += diff
return count
N,L = map(int,input().split(' '))
arr = []
for i in range(N):
arr.append(int(input()))
print(solve(arr)) |
s123801403 | p00474 | u198881450 | 1497439740 | Python | Python3 | py | Runtime Error | 0 | 0 | 940 | def greedy(N,L,ices):
counts = 1
while True:
# print(ices)
for i in range(len(ices)):
if 0 < i < N-1:
if ices[i] > ices[i-1] and ices[i] > ices[i+1]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
elif i == 0:
if ices[i] > ices[1]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
elif i == N-1:
if ices[i] > ices[N-2]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
if ices.count(0) == N:
print(counts)
return
counts += 1
N,L = input().rstrip().split()
ices = []
while True:
ice = input().rstrip()
ices.append(ice)
if len(ices) == N:
break
# N = 4
# L = 6
# ices = [4,2,3,5]
greedy(N,L,ices) |
s217259789 | p00474 | u198881450 | 1497443016 | Python | Python3 | py | Runtime Error | 0 | 0 | 1723 | import copy
def greedy(N,L,ices):
counts = 1
while True:
# print(ices)
copied = copy.deepcopy(ices)
for i in range(len(ices)):
if copied[i] != 0:
if 0 < i < N-1:
if copied[i] >= L:
ices[i] = 0
break
if copied[i] > copied[i-1] and copied[i] > copied[i+1]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
elif i == 0:
if copied[i] >= L:
ices[i] = 0
break
if copied[i] > copied[1]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
elif i == N-1:
if ices[i] >= L:
ices[i] = 0
break
if copied[i] > copied[N-2]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
copied = ices
if ices.count(0) == N:
print(counts)
return
counts += 1
# N,L = map(int,input().strip().split())
# ices = []
# while True:
# ice = int(input().strip())
# ices.append(ice)
# if len(ices) == N:
# break
# N = 4
# L = 6
# ices = [4,2,3,5]
# N = 6
# L = 10
# ices = [3,4,1,9,5,1]
with open("aoj.txt") as infile:
N,L = map(int,infile.readline().strip().split())
ices = []
while True:
ice = int(infile.readline())
ices.append(ice)
if len(ices) == N:
break
greedy(N,L,ices) |
s074419093 | p00474 | u198881450 | 1497443040 | Python | Python3 | py | Runtime Error | 40000 | 14000 | 1725 | import copy
def greedy(N,L,ices):
counts = 1
while True:
# print(ices)
copied = copy.deepcopy(ices)
for i in range(len(ices)):
if copied[i] != 0:
if 0 < i < N-1:
if copied[i] >= L:
ices[i] = 0
break
if copied[i] > copied[i-1] and copied[i] > copied[i+1]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
elif i == 0:
if copied[i] >= L:
ices[i] = 0
break
if copied[i] > copied[1]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
elif i == N-1:
if ices[i] >= L:
ices[i] = 0
break
if copied[i] > copied[N-2]:
ices[i] += 1
if ices[i] >= L:
ices[i] = 0
copied = ices
if ices.count(0) == N:
print(counts)
return
counts += 1
N,L = map(int,input().strip().split())
ices = []
while True:
ice = int(input().strip())
ices.append(ice)
if len(ices) == N:
break
# N = 4
# L = 6
# ices = [4,2,3,5]
# N = 6
# L = 10
# ices = [3,4,1,9,5,1]
# with open("aoj.txt") as infile:
# N,L = map(int,infile.readline().strip().split())
# ices = []
# while True:
# ice = int(infile.readline())
# ices.append(ice)
# if len(ices) == N:
# break
greedy(N,L,ices) |
s427739111 | p00474 | u940389926 | 1497445626 | Python | Python3 | py | Runtime Error | 0 | 0 | 1455 | N, L = 0, 0
def loadIcicle():
N, L = 0, 0
i = 0
icicles = []
line = sys.stdin.readline().strip()
while True:
if i == 0:
N, L = int(line.split(" ")[0]), int(line.split(" ")[1])
i += 1
continue
line = sys.stdin.readline().strip()
if line == "": break
icicles.append(int(line))
i += 1
if i == N+1: break
return icicles, N, L
icicles, N, L = loadIcicle()
def calcDiff(icicles, N):
diff_2times = []
for _ in range(len(icicles)):
diff_2times.append(0)
for idx in range(len(icicles)):
dif_right = icicles[idx+1] - icicles[idx] if idx != N-1 else -icicles[idx]
dif_left = icicles[idx] - icicles[idx-1] if idx != 0 else icicles[idx]
peak = dif_left * dif_right < 0
if peak and dif_left > 0: diff_2times[idx] = -1
elif peak and dif_right > 0: diff_2times[idx] = 1
else: diff_2times[idx] = 0
return diff_2times
diff_2times = calcDiff(icicles, N)
time = []
for _ in range(len(icicles)):
time.append(-1)
for i in range(len(icicles)):
if diff_2times[i] == -1:
time[i] = L - icicles[i]
for i in range(len(icicles)):
if time[i] == -1: pass
else: continue
if diff_2times[i] == 0: pass
else: continue
if time[i-1] != -1: time[i] = (L-icicles[i]) + time[i-1]
elif time[i+1] != -1: time[i] = (L-icicles[i]) + time[i+1]
for i in range(len(icicles)):
if time[i] == -1: pass
else: continue
if diff_2times[i] == 1: pass
else: continue
time[i] = (L-icicles[i]) + max(time[i-1], time[i+1])
print(max(time)) |
s888920137 | p00474 | u028939600 | 1497454626 | Python | Python | py | Runtime Error | 0 | 0 | 711 | def orderN(N,L,ices):
upPeak = L - ices[0]
downPeak = L - ices[0]
peaks = []
for i in xrange(len(ices)):
if i < N-1:
if ices[i] < ices[i+1]:
peaks.append(downPeak)
downPeak = L - ices[i+1]
upPeak += L - ices[i+1]
else:
peaks.append(upPeak)
upPeak = L - ices[i+1]
downPeak += L - ices[i+1]
else:
peaks.append(upPeak)
peaks.append(downPeak)
print(max(peaks))
N,L = map(int,rawinput().strip().split())
ices = []
while True:
ice = int(rawinput().strip())
ices.append(ice)
if len(ices) == N:
break
orderN(N,L,ices) |
s782493657 | p00474 | u028939600 | 1497494305 | Python | Python | py | Runtime Error | 0 | 0 | 675 | def orderN(N,L,ices):
upPeak = L - ices[0]
downPeak = L - ices[0]
peaks = []
for i in range(len(ices)):
if i < N-1:
if ices[i] < ices[i+1]:
peaks.append(downPeak)
downPeak = L - ices[i+1]
upPeak += L - ices[i+1]
elif ices[i] > ices[i+1]:
peaks.append(upPeak)
upPeak = L - ices[i+1]
downPeak += L - ices[i+1]
elif i == N-1:
peaks.append(upPeak)
peaks.append(downPeak)
print(max(peaks))
N,L = map(int,input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]
orderN(N,L,ices) |
s918860694 | p00474 | u940389926 | 1497534907 | Python | Python3 | py | Runtime Error | 0 | 0 | 1635 | ## ?????????
def loadIcicle():
icicles = []
line = input().strip().split(" ")
N, L = int(line[0]), int(line[1])
while True:
icicles.append(int(input().strip()))
if len(icicles) == N: break
return icicles, N, L
icicles, N, L = loadIcicle()
def calcDiff(icicles, N):
diff_2times = [0]*len(icicles)
for idx in range(len(icicles)):
dif_right = icicles[idx+1] - icicles[idx] if idx != N-1 else -icicles[idx]
dif_left = icicles[idx] - icicles[idx-1] if idx != 0 else icicles[idx]
dif_right = 1 if dif_right > 0 else -1
dif_left = 1 if dif_left > 0 else -1
if dif_right - dif_left < 0: diff_2times[idx] = -1
elif dif_right - dif_left > 0: diff_2times[idx] = 1
else: diff_2times[idx] = 0
return diff_2times
diff_2times = calcDiff(icicles, N)
time = [-1]*len(icicles)
peakX = [i for i in range(len(diff_2times)) if diff_2times[i]==-1] # ?????????(?????????)???index?????????
for i in peakX:
time[i] = L - icicles[i]
isLocalMinL, isLocalMinR = False, False
posL = i
posR = i
while not (isLocalMinL and isLocalMinR):
posL -= 1
# ?£????????????£?????????????¨????
if not isLocalMinL:
if time[posL] == -1:
time[posL] = (L-icicles[posL]) + time[posL+1]
else:
time[posL] = (L-icicles[posL]) + max(time[posL-1], time[posL+1])
# ????????????????????????
if diff_2times[posL] == 1 or posL == 0:
isLocalMinL = True
posR += 1
if not isLocalMinR:
if time[posR] == -1:
time[posR] = (L-icicles[posR]) + time[posR-1]
else:
time[posR] = (L-icicles[posR]) + max(time[posR-1], time[posR+1])
if diff_2times[posR] == 1 or posR == N-1:
isLocalMinR = True
print(max(time)) |
s300274723 | p00474 | u940389926 | 1497545180 | Python | Python3 | py | Runtime Error | 0 | 0 | 1279 | def loadIcicle():
icicles = []
line = input().strip().split(" ")
N, L = int(line[0]), int(line[1])
for _ in range(N):
icicles.append(int(input().strip()))
return icicles, N, L
def calcDiff(icicles, N):
diff_2times = [0]*N
for idx in range(N):
dif_right = icicles[idx+1] - icicles[idx] if idx != N-1 else -icicles[idx]
dif_left = icicles[idx] - icicles[idx-1] if idx != 0 else icicles[idx]
dif_right = 1 if dif_right > 0 else -1
dif_left = 1 if dif_left > 0 else -1
if dif_right - dif_left < 0: diff_2times[idx] = -1
elif dif_right - dif_left > 0: diff_2times[idx] = 1
else: diff_2times[idx] = 0
return diff_2times
icicles, N, L = loadIcicle()
diff_2times = calcDiff(icicles, N)
time = [-1]*N
peakX = [i for i in range(N) if diff_2times[i] == -1]
for i in peakX:
time[i] = L - icicles[i]
posL, posR = i, i
while True:
posL -= 1
if posL < 0: break
if not isLocalMinL:
left = 0 if posL-1 < 0 else time[posL-1]
time[posL] = (L-icicles[posL]) + max(left, time[posL+1])
if diff_2times[posL] == 1: break
while True:
posR += 1
if posR > N-1: break
if not isLocalMinR:
right = 0 if posR+1 > N-1 else time[posR+1]
time[posR] = (L-icicles[posR]) + max(time[posR-1], right)
if diff_2times[posR] == 1: break
print(max(time)) |
s075776604 | p00474 | u940389926 | 1497545624 | Python | Python3 | py | Runtime Error | 40000 | 7832 | 1367 | def loadIcicle():
icicles = []
line = input().strip().split(" ")
N, L = int(line[0]), int(line[1])
while True:
icicles.append(int(input().strip()))
if len(icicles) == N: break
return icicles, N, L
def calcDiff(icicles, N):
diff_2times = [0]*N
for idx in range(N):
dif_right = icicles[idx+1] - icicles[idx] if idx != N-1 else -icicles[idx]
dif_left = icicles[idx] - icicles[idx-1] if idx != 0 else icicles[idx]
dif_right = 1 if dif_right > 0 else -1
dif_left = 1 if dif_left > 0 else -1
if dif_right - dif_left < 0: diff_2times[idx] = -1
elif dif_right - dif_left > 0: diff_2times[idx] = 1
else: diff_2times[idx] = 0
return diff_2times
icicles, N, L = loadIcicle()
diff_2times = calcDiff(icicles, N)
time = [-1]*N
peakX = [i for i in range(N) if diff_2times[i]==-1]
for i in peakX:
time[i] = L - icicles[i]
isLocalMinL, isLocalMinR = False, False
posL, posR = i, i
while not (isLocalMinL and isLocalMinR):
posL -= 1
if posL < 0:
isLocalMinL = True
if not isLocalMinL:
left = 0 if posL-1 < 0 else time[posL-1]
time[posL] = (L-icicles[posL]) + max(left, time[posL+1])
if diff_2times[posL] == 1: isLocalMinL = True
if not isLocalMinR:
right = 0 if posR+1 > N-1 else time[posR+1]
time[posR] = (L-icicles[posR]) + max(time[posR-1], right)
if diff_2times[posR] == 1: isLocalMinR = True
print(max(time)) |
s059080085 | p00474 | u352394527 | 1525847571 | Python | Python3 | py | Runtime Error | 0 | 0 | 364 | def solve():
n,l = map(int,input().split())
length = [int(input()) for i in range(n)]
pare = [(length[i], i) for i in range(n)]
pare.sort(reverse=True)
dp = [0] * (n + 1)
for p in pare:
i = p[0]
if i == 0:
dp[i] = dp[i + 1] + (l - length[i])
else:
dp[i] = max(dp[i - 1], dp[i + 1]) + (l - length[i])
print(max(dp))
solve()
|
s647594167 | p00476 | u811733736 | 1506311035 | Python | Python3 | py | Runtime Error | 40000 | 15616 | 1549 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0553
"""
import sys
from sys import stdin
from heapq import heappop, heappush
input = stdin.readline
def solve():
pass
def main(args):
N, H = map(int, input().split())
MAX_H = H
costs = []
wells = []
for _ in range(N - 1):
di, hi = map(int, input().split())
costs.append(di)
wells.append(hi)
costs.append(0)
wells.append(0)
ans = 0
floor = 1
repeat = True
while floor < N:
# ?£????????????§N????????§??°?????§??????????????§????????????
pq = []
while H > 0:
heappush(pq, [-1 * min(MAX_H - H, wells[floor - 1]), floor, H])
c = costs[floor - 1]
H -= c
if floor >= N or H < 1:
break
floor += 1
if H > 0:
break
# ??°?????§??????????????°??????????????§??????????????§??????????????????????????°?????§????????????????????????
# ????????§???????????? min(MAX_H - H, ???????????????) ????????????
# ?????????????????¨??????????¬???????????????? MAX_H - (H + ???????????????) ??¨?????????
replenish, f, orig_H = heappop(pq)
H = min(orig_H - replenish, MAX_H)
ans += 1
# ???????????¨???????????¨????????????H?????????????????§????????????????????¢????????£????????¨???????????¢?´¢???????????´??????
floor = f
print(ans)
if __name__ == '__main__':
main(sys.argv[1:]) |
s150254412 | p00476 | u811733736 | 1506338728 | Python | Python3 | py | Runtime Error | 40000 | 15652 | 1830 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0553
"""
import sys
from sys import stdin
from heapq import heappop, heappush
input = stdin.readline
def main(args):
N, H = map(int, input().split())
MAX_H = H
costs = []
wells = []
for _ in range(N - 1):
di, hi = map(int, input().split())
costs.append(di)
wells.append(hi)
costs.append(1e7)
wells.append(0)
ans = 0
floor = 1
while floor < N:
# ?£????????????§N????????§??°?????§??????????????§????????????
pq = []
while H > 0:
if H != MAX_H:
heappush(pq, [-1 * min(MAX_H-H, wells[floor - 1]), -floor, wells[floor - 1], H])
c = costs[floor - 1]
H -= c
floor += 1
if floor > N:
break
# ??°?????§??????????????°??????????????§??????????????§??????????????????????????°?????§????????????????????????
# ????????§???????????? min(MAX_H - H, ???????????????) ????????????
# ?????????????????¨??????????¬???????????????? MAX_H - (H + ???????????????) ??¨?????????
replenish, f, replenish_orig, orig_H = heappop(pq)
# if replenish == -replenish_orig:
# if H == 0:
# rep = 1
# else:
# rep = -H // replenish_orig
# if H % replenish_orig != 0:
# rep += 1
#
# H = orig_H + (replenish_orig * rep)
# ans += rep
# else:
H = orig_H - replenish
ans += 1
# ???????????¨???????????¨????????????H?????????????????§????????????????????¢????????£????????¨???????????¢?´¢???????????´??????
floor = -f
print(ans)
if __name__ == '__main__':
main(sys.argv[1:]) |
s582936170 | p00476 | u811733736 | 1507118353 | Python | Python3 | py | Runtime Error | 40000 | 15688 | 3587 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0553
"""
import sys
from sys import stdin
from heapq import heappop, heappush
import time
input = stdin.readline
class RMQ(object):
INT_MAX = 2**31 - 1
def __init__(self, nn):
self.n = 1
while self.n < nn:
self.n *= 2
self.dat = [RMQ.INT_MAX] * ((2 * self.n)-1)
def update(self, k, a):
# A[k]???a?????´??°?????????????????°???????????¨?????´??°
k += (self.n - 1)
self.dat[k] = a
while k > 0:
k = (k - 1) // 2 # ??????index??????
self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2]) # ???????????¨??????????????????????°?????????????????????´??°
def add(self, k, a):
# A[k]???a??????????????????????????°???????????¨?????´??°
k += (self.n - 1)
self.dat[k] += a
while k > 0:
k = (k - 1) // 2 # ??????index??????
self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2]) # ???????????¨??????????????????????°?????????????????????´??°
def query(self, a, b, k, l, r):
# [a, b)???????°????????±??????? (0????????§b???????????????)
# ??????????????¨?????????query(a, b, 0, 0, n)?????¢??§??????????????????k, l, r???????????????????????´??°?????????
if r <= a or b <= l: # ?????????????????§??¨??????????????????
return RMQ.INT_MAX
if a <=l and r <= b:
return self.dat[k] # ???????????°???????????????????????§????????°????????¨??????????????????????°?????????????????????????
else:
vl = self.query(a, b, k*2+1, l, (l+r)//2) # ????????°????????????????°????
vr = self.query(a, b, k*2+2, (l+r)//2, r) # ????????°????????????????°????
return min(vl, vr)
def find(self, s, t):
return self.query(s, t+1, 0, 0, self.n)
def solve_hq(N, H, costs, wells):
MAX_H = H
ans = 0
floor = 1
repeat = True
while floor < N:
# ?£????????????§N????????§??°?????§??????????????§????????????
pq = []
while H > 0:
deficit = MAX_H - H
if deficit != 0:
heappush(pq, [-1 * min(MAX_H - H, wells[floor - 1]), wells[floor - 1], floor, H])
c = costs[floor - 1]
H -= c
if floor >= N or H < 1:
break
floor += 1
if H > 0:
return ans
# ??°?????§??????????????°??????????????§??????????????§??????????????????????????°?????§????????????????????????
# ????????§???????????? min(MAX_H - H, ???????????????) ????????????
# ?????????????????¨??????????¬???????????????? MAX_H - (H + ???????????????) ??¨?????????
replenish, replenish_orig, f, orig_H = heappop(pq)
H = min(orig_H - replenish, MAX_H)
ans += 1
# ???????????¨???????????¨????????????H?????????????????§????????????????????¢????????£????????¨???????????¢?´¢???????????´??????
floor = f
def main(args):
# start = time.clock()
N, H = map(int, input().split())
costs = []
wells = []
for _ in range(N - 1):
di, hi = map(int, input().split())
costs.append(di)
wells.append(hi)
costs.append(0)
wells.append(0)
ans = solve_hq(N, H, costs, wells)
print(ans)
# end = time.clock()
# print('elapsed: {}'.format(end - start))
if __name__ == '__main__':
main(sys.argv[1:]) |
s897465492 | p00478 | u235282710 | 1443690841 | Python | Python3 | py | Runtime Error | 0 | 0 | 145 |
keyword = raw_input()
N = int(raw_input())
count = 0
for _ in xrange(N):
s = raw_input()
if keyword in (s+s):
count += 1
print count |
s377655084 | p00479 | u145563629 | 1430825774 | Python | Python | py | Runtime Error | 19930 | 4252 | 611 | N = int(raw_input())
k = int(raw_input())
while k:
k -= 1
x, y = map(int, raw_input().split())
two = 0
while 1:
a_y = two + 1
a_x = two + 1
f = 0
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_y += 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_x += 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_y -= 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_x -= 1
if f == 1:
print two % 3 + 1
break
two += 1 |
s403129742 | p00479 | u145563629 | 1430826408 | Python | Python | py | Runtime Error | 19930 | 4264 | 650 | N = int(raw_input())
k = int(raw_input())
lis = []
while k:
k -= 1
x, y = map(int, raw_input().split())
two = 0
while 1:
a_y = two + 1
a_x = two + 1
f = 0
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_y += 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_x += 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_y -= 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_x -= 1
if f == 1:
lis.append(two % 3 + 1)
break
two += 1
for i in lis:
print i |
s242477027 | p00479 | u145563629 | 1430827764 | Python | Python | py | Runtime Error | 19930 | 4268 | 688 | N = int(raw_input())
k = int(raw_input())
lis = []
while k:
k -= 1
x, y = map(int, raw_input().split())
two = 0
f = 0
while f != 1:
a_y = two + 1
a_x = two + 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_y += 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_x += 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_y -= 1
for i in range(N - two * 2 - 1):
if x == a_x and y == a_y:
f = 1
break
a_x -= 1
if N % 2 == 1 and two >= N / 2 + 1:
break
two += 1
lis.append((two - 1) % 3 + 1)
for i in lis:
print i |
s381579662 | p00479 | u560838141 | 1364457064 | Python | Python | py | Runtime Error | 0 | 0 | 128 | s = input()
n = input()
for i in range(n):
x, y = input()-1, input()-1
p = min(x, y, s - x - 1, s - y - 1)
print p % 3 + 1 |
s024923712 | p00479 | u104911888 | 1375353316 | Python | Python | py | Runtime Error | 170 | 12144 | 346 | N=input()
L=[[0]*N for i in range(N)]
R,B,Y=1,2,3
C=R
for y in range(N/2+1):
for x in range(y,N-y):
L[y][x]=C
L[N-y-1][x]=C
C=C%3+1
C=R
for x in range(N/2+1):
for y in range(x,N-x):
L[y][x]=C
L[y][N-x-1]=C
C=C%3+1
for i in range(input()):
a,b=map(int,raw_input().split())
print L[b-1][a-1] |
s840984216 | p00480 | u227162786 | 1490179975 | Python | Python3 | py | Runtime Error | 0 | 0 | 510 | while True:
N = int(input())
if N == 0:
break
a = list(map(int, input().split()))
## dp[i][j]: i???????????°????????§??§j????????????????????°
dp = [[0 for j in range(21)] for i in range(N-1)]
dp[0][a[0]] = 1
for i in range(1, N-1):
for j in range(21):
if (j - a[i]) in range(21):
dp[i][j] += dp[i-1][j-a[i]]
if (j + a[i]) in range(21):
dp[i][j] += dp[i-1][j+a[i]]
print(dp[N-2][a[N-1]]) |
s232391770 | p00480 | u227162786 | 1490180034 | Python | Python3 | py | Runtime Error | 0 | 0 | 441 | while True:
N = int(input())
if N == 0:
break
a = list(map(int, input().split()))
dp = [[0 for j in range(21)] for i in range(N-1)]
dp[0][a[0]] = 1
for i in range(1, N-1):
for j in range(21):
if (j - a[i]) in range(21):
dp[i][j] += dp[i-1][j-a[i]]
if (j + a[i]) in range(21):
dp[i][j] += dp[i-1][j+a[i]]
print(dp[N-2][a[N-1]]) |
s721629079 | p00480 | u469154576 | 1495612248 | Python | Python3 | py | Runtime Error | 0 | 0 | 357 | n = int(input())
a = list(map(int, input().split()))
dp = [[0] * 21 for i in range(n)]
dp[0][0] = 1
for i in range(n - 1):
for j in range(21):
if dp[i][j] == 0:
continue
if 0 <= j + a[i] <= 20:
dp[i + 1][j + a[i]] += dp[i][j]
if 0 <= j - a[i] <= 20:
dp[i + 1][j - a[i]] += dp[i][j]
print(dp[n - 1][a[n - 1]]) |
s254877058 | p00480 | u371539389 | 1496037461 | Python | Python3 | py | Runtime Error | 40000 | 7636 | 498 | def calc(num,ans):
if len(num)==1:
if num[0]==ans:
return 1
else:
return 0
else:
a=num.copy()
x=a.pop(-1)
if ans-x>=0 and ans+x<=20:
return calc(a,ans-x)+calc(a,ans+x)
elif ans-x>=0:
return calc(a,ans-x)
elif ans+x<=20:
return calc(a,ans+x)
else:
return 0
N=int(input())
number=[int(i) for i in input().split(" ")]
a=number.pop(-1)
print(calc(number,a)) |
s245454376 | p00480 | u228488524 | 1512970956 | Python | Python3 | py | Runtime Error | 0 | 0 | 424 | n = int(input)
inp = input()
nums = [int(i) for i in inp.split()]
ans = nums[-1]
dp = [[0 for j in range(21)] for i in range(n)]
dp[0][nums[0]] = 1
for i in range(1,n-1):
for j in range(21):
if dp[i-1][j] == 0:
continue
p = j + nums[i]
if p <= 20:
dp[i][p] += dp[i-1][j]
m = j - nums[i]
if m >= 0:
dp[i][m] += dp[i-1][j]
print(dp[n-2][ans]) |
s501255635 | p00480 | u228488524 | 1512971240 | Python | Python3 | py | Runtime Error | 0 | 0 | 413 | n = int(input)
nums = [int(i) for i in input().split()]
ans = nums[-1]
dp = [[0 for j in range(21)] for i in range(n)]
dp[0][nums[0]] = 1
for i in range(1,n-1):
for j in range(21):
if dp[i-1][j] == 0:
continue
p = j + nums[i]
if p <= 20:
dp[i][p] += dp[i-1][j]
m = j - nums[i]
if m >= 0:
dp[i][m] += dp[i-1][j]
print(dp[-1][ans]) |
s653125441 | p00480 | u104911888 | 1386318788 | Python | Python | py | Runtime Error | 0 | 0 | 367 | n = input()
s = map(int, raw_input().split())
ans = s[-1]
dp = [[0] * 21 for i in range(n)]
dp[0][s[0]] = 1
for i in range(1, n-1):
for j in range(21):
if dp[i-1][j] == 0: continue
vp = j + s[i]
vm = j - s[i]
if vp <= 20:
dp[i][vp] += dp[i-1][j]
if 0 <= vm:
dp[i][vm] += dp[i-1][j]
print dp[n-2][ans |
s236704328 | p00481 | u617183767 | 1421114799 | Python | Python | py | Runtime Error | 19930 | 57436 | 1577 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import itertools
import math
from collections import Counter, defaultdict
class Main(object):
def __init__(self):
pass
def solve(self):
'''
insert your code
'''
h, w, n = map(int, raw_input().split())
board = [[None for j in range(w+1)] for i in range(h+1)]
s = (None, None)
nxt = 1
ans = 0
for i in range(1, h+1):
row = raw_input()
for j in range(1, w+1):
board[i][j] = row[j-1]
if board[i][j] == 'S':
s = (i, j, ans)
# print board
# print s
# print board[3][3]
d = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# print nxt
q = [s]
while nxt <= n:
while q != []:
y, x, ans = q.pop(0)
# print y, x, ans, nxt
# if (y, x) == (3, 3):
# print nxt
# print board[y][x]
# print nxt == board[y][x]
if board[y][x] == str(nxt):
nxt += 1
q = [(y, x, ans)]
# print 'nxt: ' + str(nxt)
break
ans += 1
for dy, dx in d:
if 0 < y + dy <= h and 0 < x + dx <= w and board[y+dy][x+dx] != 'X':
q.append((y + dy, x + dx, ans))
print ans
return None
if __name__ == '__main__':
m = Main()
m.solve() |
s187970296 | p00481 | u617183767 | 1421117313 | Python | Python | py | Runtime Error | 19930 | 141836 | 2015 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import itertools
import math
from collections import Counter, defaultdict
class Main(object):
def __init__(self):
pass
def solve(self):
'''
insert your code
'''
h, w, n = map(int, raw_input().split())
board = [[None for j in range(w+1)] for i in range(h+1)]
s = (None, None)
ans = 0
for i in range(1, h+1):
row = raw_input()
for j in range(1, w+1):
board[i][j] = row[j-1]
if board[i][j] == 'S':
s = (i, j, ans, [])
elif board[i][j] == '1':
g = (i, j)
# print board
# print s
# print board[3][3]
d = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# print nxt
q = [s]
for nxt in range(1, n+1):
# print q
while q != []:
y, x, ans, used = q.pop(0)
# print y, x, ans, used
# if (y, x) == (3, 3):
# print nxt
# print board[y][x]
# print nxt == board[y][x]
# if board[y][x] == str(nxt):
# q = [(y, x, ans)]
# # print 'nxt: ' + str(nxt)
# break
if y == g[0] and x == g[1]:
break
ans += 1
for dy, dx in d:
if 0 < y + dy <= h and 0 < x + dx <= w and board[y+dy][x+dx] != 'X' and (not (y + dy, x + dx) in used):
q.append((y + dy, x + dx, ans, used + [(y, x)]))
q = [(y, x, ans, [])]
for i in range(1, h+1):
for j in range(1, w+1):
if board[i][j] == str(nxt+1):
g = (i, j)
# print q
print ans
return None
if __name__ == '__main__':
m = Main()
m.solve() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.