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
s683590435
p00754
u316268279
1421244310
Python
Python3
py
Runtime Error
19920
6720
705
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**6) def dfs(string,bracket): i = 0 while i < len(string): if bracket == '[' and string[i] == ']': return i elif bracket == '(' and string[i] == ')': return i elif string[i] == '(' or string[i] == '[': ret = dfs(string[i+1:],string[i]) ret += 1 if ret == False: return False i += ret i += 1 return True if bracket == '' else False while True: string = list(input()) if len(string) == 1 and string[0] == '.': break ans = 'yes' if dfs(string,'') else 'no' print(ans)
s714579402
p00754
u966364923
1436701258
Python
Python3
py
Runtime Error
0
0
589
while True: flg = True S = input() if S = '.': exit() cnt = [0, 0] for c in S: if c == '[': cnt[0] += 1 elif c == ']': cnt[0] -= 1 if cnt[0] < 0: flg = False break elif c == '(': cnt[1] += 1 elif c == ')': cnt[1] -= 1 if cnt[1] < 0: flg = False break else: pass if cnt[0]>0 or cnt[1]>0: flg = False if flg: print('yes') else: print('no')
s106650652
p00754
u269391636
1523771296
Python
Python3
py
Runtime Error
0
0
607
while (True): st = input() st = [i for i in st if i in ["(",")","[","]"] han = [] ans = "Yes" for i in st: if i == "(": han.append("maru") elif i == "[": han.append("kaku") elif i == ")": if han == []: ans = "No" break elif han[-1] == "maru": del han[-1] else: ans = "No" break elif i == "[": if han == []: ans = "No" break elif han[-1] == "kaku": del han[-1] else: ans = "No" break if ans == "No" or han != []: print("No") else: print(ans)
s370658828
p00755
u685815919
1479112370
Python
Python
py
Runtime Error
40000
6564
1440
import copy import heapq vec=[(0,1),(0,-1),(1,0),(-1,0)] def printField(field): for i in xrange(len(field)): print "".join(map(str,field[i])) def counter(field): c=field[0][0] field[0][0]=0 q=[] count=1 heapq.heappush(q,(0,0)) while q: x,y=heapq.heappop(q) for dx,dy in vec: if x+dx<0 or len(field)<=x+dx or y+dy<0 or len(field[0])<=y+dy: continue if field[x+dx][y+dy]==c: count+=1 field[x+dx][y+dy]=0 heapq.heappush(q,(x+dx,y+dy)) return count def changeColor(c, field): newField=copy.deepcopy(field) newField[0][0]=c q=[] changed={} heapq.heappush(q,(0,0)) changed[(0,0)]=True while q: x,y=heapq.heappop(q) for dx,dy in vec: if x+dx<0 or len(field)<=x+dx or y+dy<0 or len(field[0])<=y+dy: continue if newField[x+dx][y+dy]==field[0][0]: if (x+dx,y+dy) not in changed: newField[x+dx][y+dy]=c changed[(x+dx,y+dy)]=True heapq.heappush(q,(x+dx,y+dy)) return newField def electro(count, field, last): if count==4: newField=changeColor(last, field) return counter(newField) maxSize=0 for i in xrange(1,7): newField=changeColor(i, field) maxSize=max(maxSize, electro(count+1,newField,last)) return maxSize while True: h,w,c=map(int,raw_input().split()) if h==0: break field=[] for i in xrange(h): field.append(map(int,raw_input().split())) print electro(0,field,c)
s673990055
p00755
u408260374
1495217737
Python
Python3
py
Runtime Error
40000
8068
1375
import copy import itertools drc = [(-1, 0), (0, 1), (1, 0), (0, -1)] C_NUM = 6 while True: H, W, C = map(int, input().split()) if not (H | W | C): break board = [[int(x) - 1 for x in input().split()] for _ in range(H)] ans = 0 for ope in itertools.product(range(C_NUM), repeat=4): # print(ope) tmp_board = copy.deepcopy(board) for color in itertools.chain(ope, (C - 1,)): now_c = tmp_board[0][0] if now_c == color: continue stack = [(0, 0)] while stack: r, c = stack.pop() if tmp_board[r][c] == color: continue tmp_board[r][c] = color for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == now_c: stack.append((nr, nc)) stack = [(0, 0)] while stack: r, c = stack.pop() if tmp_board[r][c] == -1: continue tmp_board[r][c] = -1 for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == C - 1: stack.append((nr, nc)) ans = max(ans, sum(row.count(-1) for row in tmp_board)) print(ans)
s051483273
p00755
u408260374
1495217841
Python
Python
py
Runtime Error
40000
6516
1450
import copy import itertools import sys if sys.version[0] == '2': range, input = xrange, raw_input drc = [(-1, 0), (0, 1), (1, 0), (0, -1)] C_NUM = 6 while True: H, W, C = map(int, input().split()) if not (H | W | C): break board = [[int(x) - 1 for x in input().split()] for _ in range(H)] ans = 0 for ope in itertools.product(range(C_NUM), repeat=4): # print(ope) tmp_board = copy.deepcopy(board) for color in itertools.chain(ope, (C - 1,)): now_c = tmp_board[0][0] if now_c == color: continue stack = [(0, 0)] while stack: r, c = stack.pop() if tmp_board[r][c] == color: continue tmp_board[r][c] = color for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == now_c: stack.append((nr, nc)) stack = [(0, 0)] while stack: r, c = stack.pop() if tmp_board[r][c] == -1: continue tmp_board[r][c] = -1 for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == C - 1: stack.append((nr, nc)) ans = max(ans, sum(row.count(-1) for row in tmp_board)) print(ans)
s446203275
p00755
u408260374
1495218809
Python
Python
py
Runtime Error
40000
6576
1475
import copy import itertools import sys if sys.version[0] == '2': range, input = xrange, raw_input drc = [(-1, 0), (0, 1), (1, 0), (0, -1)] C_NUM = 6 while True: H, W, C = map(int, input().split()) if not (H | W | C): break board = [[int(x) - 1 for x in input().split()] for _ in range(H)] ans = 0 for ope in itertools.product(range(C_NUM), repeat=4): # print(ope) ps = [(0, 0)] tmp_board = copy.deepcopy(board) for color in itertools.chain(ope, (C - 1,)): now_c = tmp_board[0][0] if now_c == color: continue for r, c in ps: tmp_board[r][c] = color stack = ps[:] while stack: r, c = stack.pop() for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == now_c: tmp_board[nr][nc] = color stack.append((nr, nc)) for r, c in ps: tmp_board[r][c] = -1 stack = ps[:] while stack: r, c = stack.pop() for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == C - 1: tmp_board[nr][nc] = -1 stack.append((nr, nc)) ans = max(ans, sum(row.count(-1) for row in tmp_board)) print(ans)
s066088557
p00755
u408260374
1495219048
Python
Python
py
Runtime Error
40000
6592
1520
import copy import itertools import sys if sys.version[0] == '2': range, input = xrange, raw_input drc = [(-1, 0), (0, 1), (1, 0), (0, -1)] C_NUM = 6 while True: H, W, C = map(int, input().split()) if not (H | W | C): break board = [[int(x) - 1 for x in input().split()] for _ in range(H)] ans = 0 for ope in itertools.product(range(C_NUM), repeat=4): # print(ope) ps = [(0, 0)] tmp_board = copy.deepcopy(board) for color in itertools.chain(ope, (C - 1,)): now_c = tmp_board[0][0] if now_c == color: continue for r, c in ps: tmp_board[r][c] = color stack = ps[:] while stack: r, c = stack.pop() for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == now_c: tmp_board[nr][nc] = color stack.append((nr, nc)) ps.append((nr, nc)) for r, c in ps: tmp_board[r][c] = -1 stack = ps[:] while stack: r, c = stack.pop() for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < H and 0 <= nc < W and tmp_board[nr][nc] == C - 1: tmp_board[nr][nc] = -1 stack.append((nr, nc)) ans = max(ans, sum(row.count(-1) for row in tmp_board)) print(ans)
s863643143
p00755
u104911888
1370907669
Python
Python
py
Runtime Error
20000
4372
1213
from copy import deepcopy dx=[0,0,1,-1] dy=[1,-1,0,0] def dfs(y,x,color,precolor): if color==precolor: return P[y][x]=color for i in range(4): mx=x+dx[i] my=y+dy[i] if 0<=mx<w and 0<=my<h and P[my][mx]==precolor: dfs(my,mx,color,precolor) def panelnum(y,x,color): global cnt if P[y][x]==color: P[y][x]="B" cnt+=1 else: return cnt for i in range(4): mx=x+dx[i] my=y+dy[i] if 0<=mx<w and 0<=my<h and P[my][mx]==color: panelnum(my,mx,color) return cnt while True: h,w,c=map(int,raw_input().split()) if h==w==c==0:break Panel=[map(int,raw_input().split()) for i in range(h)] maxInt=0 for i in range(1,7): for j in range(1,7): for k in range(1,7): for l in range(1,7): cnt=0 P=deepcopy(Panel) dfs(0,0,i,P[0][0]) dfs(0,0,j,P[0][0]) dfs(0,0,k,P[0][0]) dfs(0,0,l,P[0][0]) dfs(0,0,c,P[0][0]) s=panelnum(0,0,c) maxInt=max(maxInt,s) print maxInt
s817009003
p00756
u852216820
1530816437
Python
Python3
py
Runtime Error
0
0
1115
def xx(x): return x * x def pop(overlaps, i, lis): for k in lis: if i > k and overlaps[i][k]: return False return True def search(disks, overlaps, lis): if len(lis) < 2: return 0 res = 0 for i in lis: if not pop(overlaps, i, lis): continue #print("OK", i) for k in lis: if i == k: continue if disks[i][3] != disks[k][3]: continue if not pop(overlaps, k, lis): continue #print("Good", k) giv = list(lis) giv.remove(i) giv.remove(k) res = max(res, 2 + search(disks, overlaps, giv)) return res while True: n = int(input()) if n == 0: break disks = [ list(map(int, input().split(" "))) for _ in range(n) ] overlaps = [] for i in range(n): res = [] for k in range(n): a = disks[i]; b = disks[k] res.append(xx(a[0] - b[0]) + xx(a[1] - b[1]) < xx(a[2] + b[2])) overlaps.append(res) #print(overlaps) print(search(disks, overlaps, list(range(n))))
s125827437
p00757
u269391636
1526232397
Python
Python3
py
Runtime Error
0
0
1880
#教室内の位置は右*中央 #問題は「Eleven Lover」(http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2182&lang=jp) #本当は問題「Planning Rolling Blackouts」(http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1176&lang=jp) #を解こうとしたのですが、小区間での分割をひたすら統合する解法までは立ったものの実装力がなかったので一旦やめました while(True): #今回はinputの数字を文字列として一桁ずつ扱った方が嬉しいのでint()しません s = input() m = len(s) #0を弾くやつ if s == "0": quit() #pdfに書いていた方針と全く同じやり方をします #配列dpをA_i,jとしてとります dp = [[0 for j in range(11)] for i in range(m)] for i in range(m): n = int(s[i]) #ここで、どこかの桁が0になってる時に注意します #というのも、問題文中に「0から始まる数は11の倍数に含めない」としてあるからです #したがって0が出た時はそこまでの数字を10倍する効果しか持たないことになります if n == 0: tmp = dp[i-1][1:] tmp.reverse() #dp[i][0]=dp[i-1][0] #dp[i][k]=dp[i-1][11-k] (if k >= 1)となります(これがtmp.reverse()の意図) dp[i] = [dp[i-1][0]]+tmp else: #やるだけ tmp = dp[i-1][1:] tmp.reverse() #10倍なのでA[i][k] (k>=1)をリバース(上と同じ) tmp = [dp[i-1][0]]+tmp #i桁目の数字を見てその分A_i,jをずらします #添字に注意 dp[i] = tmp[-n:]+tmp[:-n] dp[i][n] += 1 #インクリメントも忘れずに #あとはdp[k][0]を足すだけ print(sum([i[0] for i in dp]))
s496744180
p00760
u300645821
1413361299
Python
Python
py
Runtime Error
0
0
230
#!/usr/bin/python import sys if sys.version_info[0]>=3: raw_input=input n=int(raw_input()) for i in range(0,n): y,m,d=[int(e) for e in raw_input().split()] y-=1;m-=1 print(196471-y*195-y//3*5-m*20+(m//2 if y%3!=2 else 0)-a[2])
s817353191
p00760
u940190657
1436687628
Python
Python3
py
Runtime Error
0
0
811
#solve function def solve(dates): counter = 0; start_month = dates[1] start_day, end_day = dates[2], 0 for year in range(dates[0], 1000): for month in range(start_month, 11): if year%3 == 0 or month%2 == 1: end_day = 21 else: end_day = 20 # count days counter += (end_day - start_day) start_day = 1 else: start_month = 1 return counter #main function if __name__ == '__main__': n = int(input()) dates = [] tmp_dates = [] for i in range(n): tmp_dates = input().split() for j, tmp_date in enumerate(tmp_dates): dates.append(int(tmp_date)) date_count = solve(dates) print(date_count) dates.clear()
s782081518
p00760
u940190657
1436687701
Python
Python3
py
Runtime Error
0
0
806
#solve function def solve(dates): counter = 0; start_month = dates[1] start_day, end_day = dates[2], 0 for year in range(dates[0], 1000): for month in range(start_month, 11): if year%3 == 0 or month%2 == 1: end_day = 21 else: end_day = 20 # count days counter += (end_day - start_day) start_day = 1 else: start_month = 1 return counter #main function if __name__ == '__main__': n = int(input()) dates = [] tmp_dates = [] for i in range(n): tmp_dates = input().split() for j in range(len(tmp_dates)): dates.append(int(tmp_dates[j])) date_count = solve(dates) print(date_count) dates.clear()
s982842458
p00760
u922871577
1482211226
Python
Python
py
Runtime Error
0
0
711
N = int(raw_input()) D1 = 20*5 + 19*5 D2 = 20*10 for i in xrange(N): y, m, d = map(int, raw_input().split()) ans = 0 if d != 1: if y % 3 == 0 or m % 2 == 1: last = 20 else: last = 19 ans += last - d + 1 d = 1 if m < 10: m += 1 else: y += 1 m = 1 if m != 1: while m < 11: if y % 3 == 0 or m % 2 == 1: ans += 20javascript:void(0); else: ans += 19 m += 1 m = 1 y += 1 while y < 1000: if y % 3 == 0: ans += D2 else: ans += D1 y += 1 print ans
s781814784
p00760
u814249052
1370879696
Python
Python
py
Runtime Error
0
0
899
def datesOfTheYear(year): if year % 3 == 0: return 200 return 195 def datesOfTheMonth(year, month): if year % 3 == 0: return 20 if month % 2 == 0: return 19 else: return 20 def datesFromBorn(birthyear, birthmonth, birthdate): result = 0 for y in range(birthyear + 1, 1000): result += datesOfTheYear(y) for m in range(birthmonth + 1, 11): result += datesOfTheMonth(birthyear, m) result += datesOfTheMonth(birthyear, birthmonth) - birthdate + 1 return result if __name__ == "__main__": import sys import fileinput fin = fileinput.input() numberofcandidate = int(fin.next().sprit()) for _ in range(numberofcandidate): year, month, date = fin.next().strip().split() print datesFromBorn(year, month, date) sys.exit(0)
s759239118
p00760
u300645821
1400581158
Python
Python3
py
Runtime Error
0
0
193
import sys n=int(sys.stdin.readline()) for i in range(0,n): a=map(int,sys.stdin.readline().split()) a[0]-=1;a[1]-=1 print(196471-a[0]*195-a[0]/3*5-a[1]*20+(a[1]/2 if a[0]%3!=2 else 0)-a[2])
s881294116
p00760
u300645821
1400581257
Python
Python
py
Runtime Error
0
0
210
import sys if sys.version_info[0]>=3: raw_input=input n=int(raw_input()) for i in range(0,n): a=map(int,raw_input()) a[0]-=1;a[1]-=1 print(196471-a[0]*195-a[0]/3*5-a[1]*20+(a[1]/2 if a[0]%3!=2 else 0)-a[2])
s521102209
p00760
u300645821
1400581351
Python
Python3
py
Runtime Error
0
0
218
import sys if sys.version_info[0]>=3: raw_input=input n=int(raw_input()) for i in range(0,n): a=map(int,raw_input().split()) a[0]-=1;a[1]-=1 print(196471-a[0]*195-a[0]/3*5-a[1]*20+(a[1]/2 if a[0]%3!=2 else 0)-a[2])
s878848177
p00761
u328199937
1556032584
Python
Python3
py
Runtime Error
0
0
741
def pluss_zero(a, L): a = str(a) while len(a) < L: a = "0" + a return a def make_maxminnum(a): a = list(a) a.sort() maxa = int("".join(a[::-1])) mina = int("".join(a)) return maxa - mina ans_list = [] while True: a, L = map(int, input().split()) if a == 0 and L == 0: break a_list = [a] for i in range(20): a = make_maxminnum(pluss_zero(a, L)) a_list.append(a) ans = 0 for i in range(20): for j in range(20): if i < j and a_list[i] == a_list[j]: ans = [str(i), str(a_list[i]), str(j - i)] break if ans: break ans_list.append(ans) for i in ans_list: print(" ".join(i))
s079280686
p00761
u136916346
1530195409
Python
Python3
py
Runtime Error
0
0
328
while 1: a,p=map(int,input().split()) if not a and not p:break a=str(a).zfill(p) b=[a] f=lambda l:int("".join(l)) for j in range(10): m=sorted(a) a=str(f(m[::-1])-f(m)).zfill(p) if a in b: i=b.index(a) break b.append(a) print(i,int(a),j+1-i)
s518238666
p00762
u112036414
1559045044
Python
Python3
py
Runtime Error
0
0
3049
false=False true=True dices={} me=[0,0,0,0,0,0] def getDice(x,y,z): return dices["{},{},{}".format(x,y,z)] def setDice(x,y,z,top,ground=False): dices["{},{},{}".format(x,y,z)]=top me[top]+=1 if not ground: me[getDice(x,y,z-1)]-=1 while True: n=int(input()) if n==0: break ######### Z=0 for i in range(n): top,fwd=map(int,input().split()) x=0,y=0,z=Z+1 while True: if z==0 : setDice(x,y,z,top,True) break never=True def canContinue(smx,smy,lgx,lgy): small=getDice(x+smx,y+smy,z-1) large=getDice(x+lgx,y+lgy,z-1) if large is not None: x+=lgx y-=lgy z-=1 never=False return True elif small is not None: x+=smx y+=smy z-=1 return True never=False else: return False if top==1: if fwd==2: if canContinue(-1,0,0,-1): continue elif fwd==3: if canContinue(0,-1,1,0): continue elif fwd==4: if canContinue(0,1,-1,0): continue elif fwd==5: if canContinue(1,0,0,1): continue elif top==2: if fwd==1: if canContinue(1,0,0,-1): continue elif fwd==3: if canContinue(0,-1,-1,0): continue elif fwd==4: if canContinue(0,1,1,0): continue elif fwd==6: if canContinue(-1,0,0,1): continue elif top==3: if fwd==1: if canContinue(-1,0,0,-1): continue elif fwd==2: if canContinue(0,-1,1,0): continue elif fwd==5: if canContinue(0,1,-1,0): continue elif fwd==6: if canContinue(1,0,0,1): continue elif top==4: if fwd==1: if canContinue(1,0,0,-1): continue elif fwd==2: if canContinue(0,-1,-1,0): continue elif fwd==5: if canContinue(0,1,1,0): continue elif fwd==6: if canContinue(-1,0,0,1): continue elif top==5: if fwd==1: if canContinue(-1,0,0,-1): continue elif fwd==3: if canContinue(0,-1,1,0): continue elif fwd==4: if canContinue(0,1,-1,0): continue elif fwd==6: if canContinue(1,0,0,1): continue elif top==6: if fwd==2: if canContinue(1,0,0,-1): continue elif fwd==3: if canContinue(0,-1,-1,0): continue elif fwd==4: if canContinue(0,1,1,0): continue elif fwd==5: if canContinue(-1,0,0,1): continue setDice(x,y,z,top) if never: Z+=1 break print(" ".join(me))
s802588782
p00763
u082657995
1556767147
Python
Python3
py
Runtime Error
0
0
2350
from collections import defaultdict while True: N, M, C, S, G = map(int, input().split()) if N==M==C==S==G==0: # 駅の数、路線の数10000、鉄道会社の数20、出発駅、目的地駅 break # E = [[] for _ in range(N+1)] # E[v] -> [(u, d, c), ...] # for _ in range(M): # x, y, d, c = map(int, input().split()) # d<=200 # E[x].append([y, d, c]) # E[y].append([x, d, c]) E = [[[] for _ in range(N+1)] for _ in range(C+1)] D = [[[float("inf")]*(N+1) for _ in range(N+1)] for _ in range(C+1)] for _ in range(M): x, y, d, c = map(int, input().split()) # d<=200 D[c][x][y] = min(D[c][x][y], d) D[c][y][x] = min(D[c][x][y], d) P = list(map(int, input().split())) # <= 50 Q = [] R = [] for _ in range(C): Q.append(list(map(int, input().split()))+[1<<30]) R.append(list(map(int, input().split()))) def fare(d_, c_): if d_==float("inf"): return float("inf") res = 0 q_p = 0 c_ -= 1 for q, r in zip(Q[c_], R[c_]): if q <= d_: res += (q - q_p) * r else: res += (d_ - q_p) * r break q_p = q #print(f"fare: d={d_}, c={c_+1}, res={res}") return res DD = [[float("inf")] * (N + 1) for _ in range(N + 1)] for c in range(1, C + 1): D_ = D[c] for k in range(1, N + 1): for i in range(1, N + 1): for j in range(1, N + 1): d_ = D_[i][k] + D_[k][j] if D_[i][j] > d_: D_[i][j] = d_ #print(D_) for i in range(1, N + 1): for j in range(1, N + 1): DD[i][j] = min(DD[i][j], fare(D_[i][j], c)) #print(DD) dist = defaultdict(lambda: float("inf")) q = [] start = S dist[start] = 0 heapq.heappush(q, (0, start)) while len(q) != 0: prob_cost, v = heapq.heappop(q) #print(prob_cost, v) if dist[v] < prob_cost: continue if v==G: print(prob_cost) break for u, c in enumerate(DD[v]): if dist[u] > dist[v]+c: dist[u] = dist[v]+c heapq.heappush(q, (dist[u], u)) else: print(-1)
s260060004
p00763
u082657995
1556768836
Python
Python3
py
Runtime Error
19630
16040
2451
import heapq from collections import defaultdict from functools import lru_cache from bisect import bisect_right while True: N, M, C, S, G = map(int, input().split()) if N == M == C == S == G == 0: # 駅の数、路線の数10000、鉄道会社の数20、出発駅、目的地駅 break #E = [[[] for _ in range(N + 1)] for _ in range(C + 1)] D = [[[float("inf")] * (N + 1) for _ in range(N + 1)] for _ in range(C + 1)] CE = [set() for _ in range(N+1)] for _ in range(M): x, y, d, c = map(int, input().split()) # d<=200 D[c][x][y] = min(D[c][x][y], d) D[c][y][x] = min(D[c][x][y], d) CE[c].add(x) CE[c].add(y) P = list(map(int, input().split())) # <= 50 Q = [] R = [] for _ in range(C): Q.append(list(map(int, input().split())) + [1 << 30]) R.append(list(map(int, input().split()))) cum_fare = [] for c_ in range(C): fare_ = [0] res = 0 q_p = 0 for q, r in zip(Q[c_][:-1], R[c_][:-1]): res += (q - q_p) * r q_p = q fare_.append(res) cum_fare.append(fare_) @lru_cache(maxsize=None) def fare(d_, c_): if d_==float("inf"): return float("inf") c_ -= 1 idx = bisect_right(Q[c_], d_) #print(c_, idx, cum_fare[c_], R[c_]) return cum_fare[c_][idx] + (R[c_][0] * d_ if idx==0 else (d_ - Q[c_][idx-1]) * R[c_][idx]) DD = [[float("inf")] * (N + 1) for _ in range(N + 1)] for c in range(1, C + 1): D_ = D[c] l = list(CE[c]) for k in l: for i in l: for j in l: d_ = D_[i][k] + D_[k][j] if D_[i][j] > d_: D_[i][j] = d_ # print(D_) for i in l: for j in l: DD[i][j] = min(DD[i][j], fare(D_[i][j], c)) # print(DD) dist = defaultdict(lambda: float("inf")) q = [] start = S dist[start] = 0 heapq.heappush(q, (0, start)) while len(q) != 0: prob_cost, v = heapq.heappop(q) # print(prob_cost, v) if dist[v] < prob_cost: continue if v == G: print(prob_cost) break for u, c in enumerate(DD[v]): if dist[u] > dist[v] + c: dist[u] = dist[v] + c heapq.heappush(q, (dist[u], u)) else: print(-1)
s530930538
p00763
u339921062
1498633688
Python
Python
py
Runtime Error
40000
7676
1502
while 1: n, m, C, s, g = map(int, raw_input().split()) if n == m == 0: break E = [[] for i in xrange(C)] for i in xrange(m): x, y, d, c = map(int, raw_input().split()) E[c-1].append((x-1, y-1, d)) P = map(int, raw_input().split()) Q = []; R = [] for i in xrange(C): Q.append([0] + map(int, raw_input().split())) R.append(map(int, raw_input().split())) def calc(c, z): p = P[c] q = Q[c] r = R[c] pz = 0 idx = 0 base = 0 while idx+1 < p and q[idx + 1] <= z: pz = q[idx+1] base += (q[idx+1] - q[idx]) * r[idx] idx += 1 return base + (z-pz)*r[idx] EA = [[10**18]*n for i in xrange(n)] for c in xrange(C): G = [[10**9]*n for i in xrange(n)] for j in xrange(n): G[j][j] = 0 for x, y, d in E[c]: G[x][y] = G[y][x] = d for k in xrange(n): for i in xrange(n): for j in xrange(n): G[i][j] = min(G[i][j], G[i][k] + G[k][j]) for i in xrange(n): for j in xrange(n): if G[i][j] < 10**8: EA[i][j] = EA[j][i] = min(EA[i][j], calc(c, G[i][j])) for k in xrange(n): for i in xrange(n): for j in xrange(n): EA[i][j] = min(EA[i][j], EA[i][k] + EA[k][j]) res = EA[s-1][g-1] if res < 10**8: print res else: print -1
s679460849
p00763
u339921062
1498635133
Python
Python
py
Runtime Error
40000
7744
1513
while 1: n, m, C, s, g = map(int, raw_input().split()) if n == m == 0: break E = [[] for i in xrange(C)] for i in xrange(m): x, y, d, c = map(int, raw_input().split()) E[c-1].append((x-1, y-1, d)) P = map(int, raw_input().split()) Q = []; R = [] for i in xrange(C): Q.append([0] + map(int, raw_input().split())) R.append(map(int, raw_input().split())) def calc(c, z): p = P[c] q = Q[c] r = R[c] idx = 0 base = 0 while idx+1 < p and q[idx + 1] < z: base += (q[idx+1] - q[idx]) * r[idx] idx += 1 return base + (z-q[idx])*r[idx] EA = [[10**18]*n for i in xrange(n)] for i in xrange(n): EA[i][i] = 0 for c in xrange(C): G = [[10**9]*n for i in xrange(n)] for i in xrange(n): G[i][i] = 0 for x, y, d in E[c]: G[x][y] = G[y][x] = min(G[x][y], d) for k in xrange(n): for i in xrange(n): for j in xrange(n): G[i][j] = min(G[i][j], G[i][k] + G[k][j]) for i in xrange(n): for j in xrange(n): if G[i][j] < 10**8: EA[i][j] = min(EA[i][j], calc(c, G[i][j])) for k in xrange(n): for i in xrange(n): for j in xrange(n): EA[i][j] = min(EA[i][j], EA[i][k] + EA[k][j]) res = EA[s-1][g-1] if res < 10**17: print res else: print -1
s417493950
p00763
u260980560
1498663983
Python
Python
py
Runtime Error
40000
8588
1605
while 1: N, M, C, s, g = map(int, raw_input().split()) if N == M == 0: break es = [[] for i in xrange(C)] for i in xrange(M): x, y, d, c = map(int, raw_input().split()) if not x < y: x, y = y, x es[c-1].append((x-1, y-1, d)) P = map(int, raw_input().split()) Q = []; R = [] for i in xrange(C): Q.append([0] + map(int, raw_input().split()) + [10**18]) R.append(map(int, raw_input().split())) def calc(c, z): p = P[c]; q = Q[c]; r = R[c] su = i = 0 while q[i+1] < z: su += (q[i+1] - q[i]) * r[i] i += 1 return su + (z - q[i]) * r[i] EA = {} INF = 10**18 for c in xrange(C): E = {(i, i): 0 for i in xrange(N)} for x, y, d in es[c]: E[x, y] = min(E.get((x, y), INF), d) for k in xrange(N): for i in xrange(N): for j in xrange(i+1, N): k1 = min((i, k), (k, i)) k2 = min((k, j), (j, k)) if k1 in E and k2 in E: E[i, j] = min(E.get((i, j), INF), E[k1] + E[k2]) for ps in E: EA[ps] = min(EA.get(ps, INF), calc(c, E[ps])) for k in xrange(N): for i in xrange(N): for j in xrange(i+1, N): k1 = min((i, k), (k, i)) k2 = min((k, j), (j, k)) if k1 in EA and k2 in EA: EA[i, j] = min(EA.get((i, j), INF), EA[k1] + EA[k2]) ps = min((s-1, g-1), (g-1, s-1)) print -1 if ps not in EA else EA[ps]
s218594200
p00763
u835844653
1512211111
Python
Python3
py
Runtime Error
0
0
2323
inf=1000000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare while(1): n,m,c,s,g=map(int,input().split()) if(n==m==c==s==g==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: for i in range(n+1): map0.append([]) for map1 in map0: for j in range(n+1): map1.append(inf) for i in range(1,c+1): for j in range(1,n+1): rosen[i][j][j]=0 for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 for c0,cmap in enumerate(rosen[1:]): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if cmap[i][j]>cmap[i][k]+cmap[k][j]: cmap[i][j]=cmap[i][k]+cmap[k][j] for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] ans=bigmap[s][g] print(ans if ans < inf else -1) # print(uth[1:]) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s772575476
p00763
u835844653
1512211144
Python
Python3
py
Runtime Error
0
0
2323
inf=1000000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare while(1): n,m,c,s,g=map(int,input().split()) if(n==m==c==s==g==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: for i in range(n+1): map0.append([]) for map1 in map0: for j in range(n+1): map1.append(inf) for i in range(1,c+1): for j in range(1,n+1): rosen[i][j][j]=0 for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 for c0,cmap in enumerate(rosen[1:]): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if cmap[i][j]>cmap[i][k]+cmap[k][j]: cmap[i][j]=cmap[i][k]+cmap[k][j] for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] ans=bigmap[s][g] print(ans if ans < inf else -1) # print(uth[1:]) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s780773242
p00763
u835844653
1512211484
Python
Python3
py
Runtime Error
0
0
2314
inf=1000000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: for i in range(n+1): map0.append([]) for map1 in map0: for j in range(n+1): map1.append(inf) for i in range(1,c+1): for j in range(1,n+1): rosen[i][j][j]=0 for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 for c0,cmap in enumerate(rosen[1:]): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if cmap[i][j]>cmap[i][k]+cmap[k][j]: cmap[i][j]=cmap[i][k]+cmap[k][j] for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] ans=bigmap[s][g] print(ans if ans < inf else -1) # print(uth[1:]) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s474318869
p00763
u835844653
1512212151
Python
Python3
py
Runtime Error
0
0
2303
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: for i in range(n+1): map0.append([]) for map1 in map0: for j in range(n+1): map1.append(inf) for i in range(1,c+1): for j in range(1,n+1): rosen[i][j][j]=0 for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 for c0,cmap in enumerate(rosen[1:]): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if cmap[i][j]>cmap[i][k]+cmap[k][j]: cmap[i][j]=cmap[i][k]+cmap[k][j] for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s548933858
p00763
u835844653
1512216750
Python
Python3
py
Runtime Error
0
0
2036
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: map0=init2d(map0,n) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): cmap=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s949340946
p00763
u835844653
1512217012
Python
Python3
py
Runtime Error
0
0
2042
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: map0=init2d(map0,n) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) ''' for c0,cmap in enumerate(rosen[1:]): cmap=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) ''' bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s959235246
p00763
u835844653
1512217245
Python
Python3
py
Runtime Error
0
0
2040
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: map0=init2d(map0,n) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): cmap=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s694573363
p00763
u835844653
1512217388
Python
Python3
py
Runtime Error
0
0
2040
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(0,n+1): for i in range(0,n+1): for j in range(0,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: map0=init2d(map0,n) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): cmap=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s444681220
p00763
u835844653
1512217500
Python
Python3
py
Runtime Error
0
0
2041
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): rosen.append([]) for map0 in rosen: map0=init2d(map0,n) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): cmap=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) #bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s789479237
p00763
u835844653
1512218226
Python
Python3
py
Runtime Error
0
0
2038
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen): if c0==0: continue; cmap=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s086647039
p00763
u835844653
1512218545
Python
Python3
py
Runtime Error
0
0
2072
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) c0=0 for cmap in rosen: if c0==0: c0+=1 continue cmap=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0)) c0+=1 bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s198035552
p00763
u835844653
1512218652
Python
Python3
py
Runtime Error
0
0
2016
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): cmap=floyd(cmap,n-1) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s961237361
p00763
u835844653
1512218905
Python
Python3
py
Runtime Error
0
0
2009
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if bigmap[i][j]>bigmap[i][k]+bigmap[k][j]: bigmap[i][j]=bigmap[i][k]+bigmap[k][j] return bigmap def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,cmap[i][j],c0+1)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s898295972
p00763
u835844653
1512219060
Python
Python3
py
Runtime Error
0
0
2006
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): res=bigmap for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if res[i][j]>res[i][k]+res[k][j]: res[i][j]=res[i][k]+res[k][j] return res def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): tmp=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,tmp[i][j],c0+1)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s441675224
p00763
u835844653
1512219595
Python
Python3
py
Runtime Error
0
0
2436
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): res=bigmap for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if res[i][j]>res[i][k]+res[k][j]: res[i][j]=res[i][k]+res[k][j] return res def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) ## for c0,cmap in enumerate(rosen[1:]): ## tmp=floyd(cmap,n) ## for i in range(1,n+1): ## for j in range(1,n+1): ## bigmap[i][j]=min(bigmap[i][j],calc(uth,tmp[i][j],c0+1)) for c0 in range(1,c+1): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if rosen[c0][i][j]>rosen[c0][i][k]+rosen[c0][k][j]: rosen[c0][i][j]=rosen[c0][i][k]+rosen[c0][k][j] for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,rosen[c0][i][j],c0)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s072711038
p00763
u835844653
1512219771
Python
Python3
py
Runtime Error
0
0
2435
inf=10000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): res=bigmap for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if res[i][j]>res[i][k]+res[k][j]: res[i][j]=res[i][k]+res[k][j] return res def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) ## for c0,cmap in enumerate(rosen[1:]): ## tmp=floyd(cmap,n) ## for i in range(1,n+1): ## for j in range(1,n+1): ## bigmap[i][j]=min(bigmap[i][j],calc(uth,tmp[i][j],c0+1)) for c0 in range(1,c+1): for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if rosen[c0][i][j]>rosen[c0][i][k]+rosen[c0][k][j]: rosen[c0][i][j]=rosen[c0][i][k]+rosen[c0][k][j] for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,rosen[c0][i][j],c0)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1) ''' for i in range(1,c+1): for j in range(1,n+1): for k in range(1,n+1): r=rosen[i][j][k] print(r if r<inf else -1,end='\t') print() print() '''
s550028011
p00763
u658913995
1513144794
Python
Python
py
Runtime Error
0
0
1761
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): res=bigmap for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if res[i][j]>res[i][k]+res[k][j]: res[i][j]=res[i][k]+res[k][j] return res def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): tmp=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,tmp[i][j],c0+1)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1)
s803990941
p00763
u658913995
1513145011
Python
Python
py
Runtime Error
0
0
1450
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): res=bigmap for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if res[i][j]>res[i][k]+res[k][j]: res[i][j]=res[i][k]+res[k][j] return res def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) print(-1)
s943928240
p00763
u658913995
1513145139
Python
Python
py
Runtime Error
0
0
1223
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): res=bigmap for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if res[i][j]>res[i][k]+res[k][j]: res[i][j]=res[i][k]+res[k][j] return res def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break for i in range(m): x,y,d,c0=map(int,input().split()) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) print(-1)
s586122759
p00763
u658913995
1513145159
Python
Python
py
Runtime Error
0
0
434
inf=100000000 while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break for i in range(m): x,y,d,c0=map(int,input().split()) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) print(-1)
s709050470
p00763
u658913995
1513145458
Python
Python3
py
Runtime Error
0
0
1762
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): res=bigmap for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if res[i][j]>res[i][k]+res[k][j]: res[i][j]=res[i][k]+res[k][j] return res def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigmap=[] bigmap=init2d(bigmap,n) for c0,cmap in enumerate(rosen[1:]): tmp=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): bigmap[i][j]=min(bigmap[i][j],calc(uth,tmp[i][j],c0+1)) bigmap=floyd(bigmap,n) ans=bigmap[s][g] if ans < inf: print(ans) else: print(-1)
s915874540
p00763
u658913995
1513145528
Python
Python3
py
Runtime Error
0
0
32
test = 0 while(1): test += 1
s611180125
p00763
u658913995
1513146006
Python
Python3
py
Runtime Error
0
0
9
while(1):
s607894043
p00763
u658913995
1513146022
Python
Python3
py
Runtime Error
0
0
15
while(1): 0
s266062294
p00763
u658913995
1513146788
Python
Python3
py
Runtime Error
0
0
2075
inf=100000000 def calc(uth,dis,c): fare=0 if dis>=inf: return inf if unchin[c]==1: return uth[c][1][0]*dis ddis=uth[c][0] dcost=uth[c][1] i=1 while(i<unchin[c] and dis>ddis[i]): fare+=(ddis[i]-ddis[i-1])*dcost[i-1] i+=1 fare+=(dis-ddis[i-1])*dcost[i-1] return fare def floyd(bigmap,n): res=bigmap for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): if res[i][j]>res[i][k]+res[k][j]: res[i][j]=res[i][k]+res[k][j] return res def init2d(bigmap,n): for i in range(n+1): bigmap.append([]) for map1 in bigmap: for j in range(n+1): map1.append(inf) for i in range(1,n+1): bigmap[i][i]=0 return bigmap while(1): n,m,c,s,g=map(int,input().split()) if(n==m==0): break rosen=[] for i in range(c+1): map0=[] rosen.append(init2d(map0,n)) for i in range(m): x,y,d,c0=map(int,input().split()) rosen[c0][x][y]=min(rosen[c0][x][y],d) rosen[c0][y][x]=min(rosen[c0][x][y],d) unchin=list(map(int,input().split())) unchin.insert(0,0) uth=[] uth.append([]) for i in range(1,c+1): ddis=list(map(int,input().split())) ddis.insert(0,0) dcost=list(map(int,input().split())) uth.append([ddis,dcost]) bigrosen = [] for c0,cmap in enumerate(rosen[1:]): tmp=floyd(cmap,n) for i in range(1,n+1): for j in range(1,n+1): if tmp[i][j] != inf : bigrosen.append([i,j, calc(uth,tmp[i][j],c0+1)]) bellman = [inf]*(n+1) bellman[s] = 0 for x0 in range(n): update = False for ro in bigrosen: if bellman[ro[0]]!=inf and bellman[ro[1]] > bellman[ro[0]] + ro[2]: bellman[ro[1]] = bellman[ro[0]] + ro[2] update = True if not update: break ans=bellman[g] if ans < inf: print(ans) else: print(-1)
s873194030
p00763
u072053884
1526022076
Python
Python3
py
Runtime Error
0
0
2498
def solve(): import sys from itertools import combinations from bisect import bisect from heapq import heappush, heappop file_input = sys.stdin inf = float('inf') while True: n, m, c, s, g = map(int, file_input.readline().split()) if n == 0: break # Adjacency matrices recording distances for each company adj_matrices = [[[inf] * n for j in range(n)] for i in range(c)] for i in range(m): x, y, d, c = map(int, file_input.readline().split()) mat = adj_matrices[c - 1] x -= 1 y -= 1 pre_d = mat[x][y] if d < pre_d: mat[x][y] = d mat[y][x] = d p = file_input.readline() stations = list(range(n)) # Adjacency matrix recording for the Dijkstra's algorithm adj_matrix = [[inf] * n for i in range(n)] for mat in adj_matrices: q = list(map(int, file_input.readline().split())) r = list(map(int, file_input.readline().split())) # Warshall–Floyd Algorithm for k in range(n): sc = stations.copy() del sc[k] for x, y in combinations(sc, 2): d = min(mat[x][y], mat[x][k] + mat[k][y]) mat[x][y] = d mat[y][x] = d # Fare calculation idx = bisect(q, d) fare = 0 pre_sd = 0 for sd, f in zip(q[:idx], r): fare += f * (sd - pre_sd) pre_sd = sd fare += r[idx] * (d - pre_sd) if fare < adj_matrix[x][y]: adj_matrix[x][y] = fare adj_matrix[y][x] = fare # Dijkstra's algorithm s -= 1 g -= 1 fare = [inf] * n fare[s] = 0 pq = [(0, s)] while pq: u_fare, u = heappop(pq) if u == g: print(u_fare) break for v, f in enumerate(adj_matrix[u]): new_fare = u_fare + f if new_fare < fare[v]: fare[v] = new_fare heappush(pq, (new_fare, v)) else: print(-1) solve()
s236178997
p00763
u072053884
1526022195
Python
Python3
py
Runtime Error
0
0
2420
def solve(): import sys from itertools import combinations from bisect import bisect from heapq import heappush, heappop file_input = sys.stdin inf = float('inf') while True: n, m, c, s, g = map(int, file_input.readline().split()) if n == 0: break # Adjacency matrices recording distances for each company adj_matrices = [[[inf] * n for j in range(n)] for i in range(c)] for i in range(m): x, y, d, c = map(int, file_input.readline().split()) mat = adj_matrices[c - 1] x -= 1 y -= 1 pre_d = mat[x][y] if d < pre_d: mat[x][y] = d mat[y][x] = d p = file_input.readline() stations = list(range(n)) # Adjacency list for the Dijkstra's algorithm adj_list = [[] for i in range(n)] for mat in adj_matrices: q = list(map(int, file_input.readline().split())) r = list(map(int, file_input.readline().split())) # Warshall–Floyd Algorithm for k in range(n): sc = stations.copy() del sc[k] for x, y in combinations(sc, 2): d = min(mat[x][y], mat[x][k] + mat[k][y]) mat[x][y] = d mat[y][x] = d # Fare calculation idx = bisect(q, d) fare = 0 pre_sd = 0 for sd, f in zip(q[:idx], r): fare += f * (sd - pre_sd) pre_sd = sd fare += r[idx] * (d - pre_sd) adj_list[x].append((fare, y)) adj_list[y].append((fare, x)) # Dijkstra's algorithm s -= 1 g -= 1 fare = [inf] * n fare[s] = 0 pq = [(0, s)] while pq: u_fare, u = heappop(pq) if u == g: print(u_fare) break for f, v in adj_list[u]: new_fare = u_fare + f if new_fare < fare[v]: fare[v] = new_fare heappush(pq, (new_fare, v)) else: print(-1) solve()
s049424912
p00763
u072053884
1526031563
Python
Python3
py
Runtime Error
0
0
2538
def solve(): import sys from itertools import combinations from bisect import bisect from heapq import heappush, heappop file_input = sys.stdin inf = float('inf') while True: n, m, c, s, g = map(int, file_input.readline().split()) if n == 0: break # Adjacency matrices recording distances for each company adj_matrices = [[[inf] * n for j in range(n)] for i in range(c)] for i in range(m): x, y, d, c = map(int, file_input.readline().split()) mat = adj_matrices[c - 1] x -= 1 y -= 1 pre_d = mat[x][y] if d < pre_d: mat[x][y] = d mat[y][x] = d p = file_input.readline() # Adjacency matrix recording fare for the Dijkstra's algorithm adj_matrix = [[inf] * n for i in range(n)] for mat in adj_matrices: # Warshall–Floyd Algorithm for k in range(n): for x, y in combinations(range(n), 2): d = min(mat[x][y], mat[x][k] + mat[k][y]) if d != inf: mat[x][y] = d mat[y][x] = d q = list(map(int, file_input.readline().split())) r = list(map(int, file_input.readline().split())) # Fare calculation for x, y in combinations(range(n), 2): d = mat[x][y] if d != inf: idx = bisect(q, d) fare = 0 pre_sd = 0 for sd, f in zip(q[:idx], r): fare += f * (sd - pre_sd) pre_sd = sd fare += r[idx] * (d - pre_sd) if fare < adj_matrix[x][y]: adj_matrix[x][y] = fare adj_matrix[y][x] = fare # Dijkstra's algorithm s -= 1 g -= 1 fare = [inf] * n fare[s] = 0 pq = [(0, s)] while pq: u_fare, u = heappop(pq) if u == g: print(u_fare) break for v, f in enumerate(adj_matrix[u]): new_fare = u_fare + f if new_fare < fare[v]: fare[v] = new_fare heappush(pq, (new_fare, v)) else: print(-1) solve()
s689038227
p00766
u260980560
1498651454
Python
Python
py
Runtime Error
0
0
4734
# encoding: shift-jis # Dinic algorithm from collections import deque class Dinic: def __init__(self, n): self.n = n self.g = [[] for i in xrange(n)] def add_edge(self, fr, to, cap): self.g[fr].append([to, cap, len(self.g[to])]) self.g[to].append([fr, 0, len(self.g[fr])-1]) def add_multi_edge(self, v1, v2, cap1, cap2): self.g[v1].append([v2, cap1, len(self.g[v2])]) self.g[v2].append([v1, cap2, len(self.g[v1])-1]) def bfs(self, s): level = [-1]*self.n deq = deque() level[s] = 0 deq.append(s) while deq: v = deq.popleft() for e in self.g[v]: if e[1]>0 and level[e[0]]<0: level[e[0]] = level[v] + 1 deq.append(e[0]) self.level = level def dfs(self, v, t, f): if v==t: return f es = self.g[v] level = self.level for i in xrange(self.it[v], len(self.g[v])): e = es[i] if e[1]>0 and level[v]<level[e[0]]: d = self.dfs(e[0], t, min(f, e[1])) if d>0: e[1] -= d self.g[e[0]][e[2]][1] += d self.it[v] = i return d self.it[v] = len(self.g[v]) return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.level[t]<0: break self.it = [0]*self.n while True: f = self.dfs(s, t, 10**9+7) if f>0: flow += f else: break return flow while 1: h, w = map(int, raw_input().split()) if h == w == 0: break R = [raw_input() for i in xrange(h)] conn = [[0 for i in xrange(w)] for i in xrange(h)] P = [] Q = [] dep = 0 for i in xrange(h-1): for j in xrange(w-1): # ??£?????¨???????¨???? first = R[i][j:j+2]; second = R[i+1][j:j+2] # .# ## # ## ????????? .# ?????????????????´???????????? if (first == '.#' and second == '##') or (first == '##' and second == '.#'): k = j # #. #. ## # ## ????????? #. ????????? #. ?????°??????????????§??????????????? while k+1 < w and R[i][k+1] != '.' and R[i+1][k+1] != '.': k += 1 if k+1 < w and ((R[i][k+1] == '#') ^ (R[i+1][k+1] == '#')): # #. ## # ## ????????? #. ????????????????????§(i, j)??¨(i, k)????????? P.append(((i, j), (i, k))) # (P) conn[i][j] += 1 conn[i][k] += 1 # .# #. # ## ????????? ## ?????????????????´???????????? if first in ['.#', '#.'] and second == '##': k = i # ## ## ## # #. ????????? .. ????????? .# ?????°??????????????§??????????????? while k+1 < h and R[k+1][j] != '.' and R[k+1][j+1] != '.': k += 1 if k+1 < h and ((R[k+1][j] == '#') ^ (R[k+1][j+1] == '#')): # ## ## # .# ????????? #. ????????????????????§(i, j)??¨(k, j)????????? Q.append(((i, j), (k, j))) # (Q) conn[i][j] += 1 conn[k][j] += 1 if first.count('#') + second.count('#') == 3: dep += 1 # ?????¨??°??????????§???? dinic = Dinic(2 + len(P) + len(Q)) # (s) -> (P) for i in xrange(len(P)): dinic.add_edge(0, i+2, 1) # (Q) -> (t) for i in xrange(len(Q)): dinic.add_edge(len(P)+i+2, 1, 1) # (P) -> (Q): ????????????????????????????£?????????§?????? for i, p in enumerate(P): (a, b), (a, s) = p for j, q in enumerate(Q): (c, d), (t, d) = q # ((a, b), (a, s)) ??¨ ((c, d), (t, d)) ??????????????§?????? if c <= a <= t and b <= d <= s: dinic.add_edge(i+2, len(P) + j+2, 1) # ???????????° = (???????§???° = ?????§???????????°) - (????????????????????¨?????§?????????????§???°) # # (????????????????????¨?????§?????????????????°) = (????????????????????????????????§??¬??????????????°) # => ?±??????£?????¬?????????{e1, e2}?????????????????????e1?????????e2?????????????????£???????????????????? # (?????????????????¨???????????????????????¢?????§????¨???????????????§???????????????????????) print dep - (len(P) + len(Q) - dinic.max_flow(0, 1)) + 1
s382459486
p00767
u052632641
1528450487
Python
Python
py
Runtime Error
0
0
812
import sys import math from operator import itemgetter #a = h*h + w*w #b = math.sqrt(a) mylist = [] hlist = range(1, 101) wlist = range(1, 101) for h1 in hlist: for w1 in wlist: if not w1 > h1: continue t1 = math.sqrt(pow(h1, 2) + pow(w1, 2)) mylist.append((t1, h1, w1)) mylist.sort(key=itemgetter(0)) #for t1 in mylist: # print t1 #h = int(sys.argv[1]) #w = int(sys.argv[2]) #arglist = sys.argv[1] f = open('1.txt','r') flist = f.readlines() for l in flist: hw = l.split(' ') h = int(hw[0]) w = int(hw[1]) if h == 0 and w == 0: sys.exit() t = math.sqrt(pow(h, 2) + pow(w, 2)) for t1,h1,w1 in mylist: if t > t1: continue if t == t1: if h >= h1: continue print str(h1) + " " + str(w1) break
s783541142
p00768
u136916346
1530499405
Python
Python3
py
Runtime Error
0
0
729
while 1: M,T,P,R=map(int,input().split()) if not M and not T and not P and not R:break d={i:[0,0] for i in range(1,T+1)} wa=[[0 for _ in range(P)] for _ in range(T)] for _ in range(R): m,t,p,j=map(int,input().split()) if j: wa[t-1][p-1]+=20 else: d[t][0]+=1 d[t][1]+=(m+wa[t-1][p-1]) rank=sorted(d.items(),key=lambda x:(x[1][0],-x[1][1]),reverse=True) f=lambda x:"=".join(sorted(x,key=lambda y:int(y),reverse=True)) l=[] b=[] for (i,j) in enumerate(rank): if i>0 and rank[i][1]!=rank[i-1][1]: l.append(f(b)) b=[] b.append(str(j[0])) if b:l.append(f(b)) print ",".join(l)
s828507402
p00769
u633068244
1399711261
Python
Python
py
Runtime Error
0
0
231
def solve(a): if type(a[0]) is int: return sum(sorted(a)[:len(a)/2+1])/2 + len(a) else: return sum(sorted(solve(i) for i in a))[:len(a)/2+1]) for i in range(input()): A = eval(raw_input().replace("][","],[")) print solve(A)
s353874497
p00770
u260980560
1499856018
Python
Python
py
Runtime Error
0
0
1085
from math import sqrt from collections import deque M = 10**6 prime = [1]*(M+1) prime[0] = prime[1] = 0 for i in xrange(2, int(sqrt(M))+1): if prime[i]: for j in xrange(i*i, M+1, i): prime[j] = 0 P = {(0, 0): 1}; R = [None, (0, 0)] c = 1; i = 1; p = 1 x = y = 0 while c < M: for j in xrange(i): x += p; c += 1 P[x, y] = c; R.append((x, y)) for j in xrange(i): y -= p; c += 1 P[x, y] = c; R.append((x, y)) p = -p i += 1 deq = deque() R = [-1, 0, 1] while 1: m, n = map(int, raw_input().split()) if m == n == 0: break deq.append(n) cnts = {n: prime[n]} used = set() while deq: v = deq.popleft() x, y = R[v] for dx in R: t = P.get((x+dx, y+1), M+1) if t <= m: cnts[t] = max(cnts[v] + prime[t], cnts.get(t, 0)) if t not in used: deq.append(t) used.add(t) vals = sorted((v, k) for k, v in cnts.items() if prime[k]) print "%d %d" % vals[-1] if vals else "0 0"
s811263823
p00773
u798087532
1530783965
Python
Python3
py
Runtime Error
0
0
289
while True: x,y,s = map(int,input().split(" ")) if x == 0 and y == 0 and s == 0: break fb = lambda z:z*(100+x)//100 fa = lambda z:z*(100+y)//100 ans = 0 for A in range(1,s): for B in range(1,s): if fb(A)+fb(B) != s: continue ans = max(fa(A) + fa(B),ans) print(ans)
s527248974
p00773
u798087532
1530784113
Python
Python3
py
Runtime Error
0
0
332
ret = [] while True: x,y,s = map(int,input().split(" ")) if x == 0 and y == 0 and s == 0: break fb = lambda z:z*(100+x)//100 fa = lambda z:z*(100+y)//100 ans = 0 for A in range(1,s): for B in range(1,s): if fb(A)+fb(B) != s: continue ans = max(fa(A) + fa(B),ans) ret.append(ans) for ans in ret: print(ans)
s415356467
p00773
u958378108
1530790977
Python
Python3
py
Runtime Error
0
0
439
while True: x, y, s = map(int, input().split()) if x==0 and y==0 and s==0: break else: value = 0 for a in range(1, s): for b in range(1, s): if int(a*(100+x)/100) + int(b*(100+x)/100) == s: v = int(a*(100+y)/100) + int(b*(100+y)/100) print(a,b) if value < v: value = v print(value)
s023575946
p00773
u958378108
1530791287
Python
Python3
py
Runtime Error
0
0
408
while True: x, y, s = map(int, input().split()) if x==0 and y==0 and s==0: break else: value = 0 for a in range(1, s): for b in range(1, s): if int(a*(100+x)/100) + int(b*(100+x)/100) == s: v = int(a*(100+y)/100) + int(b*(100+y)/100) if value < v: value = v print(value)
s284728627
p00773
u958378108
1530791703
Python
Python3
py
Runtime Error
0
0
438
while True: x, y, s = map(int, input().split()) if x==0 and y==0 and s==0: break else: value = 0 for a in range(1, s): for b in range(1, s-a+1): if int(a*(100+x)/100) + int(b*(100+x)/100) == s: v = int(a*(100+y)/100) + int(b*(100+y)/100) if value < v: value = v break print(value)
s436226560
p00773
u352394527
1531256975
Python
Python3
py
Runtime Error
0
0
442
#include <iostream> using namespace std; int main(void){ int x, y, s, i, j; int tmp, higher; while(cin>>x>>y>>s){ if(x == 0){ break; } higher = 0; for(i=1;i<s;i++){ for(j=i;j<s;j++){ if(i * (100 + x) / 100 + (j * (100 + x) / 100) == s){ tmp = i * (100 + y) / 100 + j * (100 + y) / 100; higher = max(higher, tmp); } } } cout<<higher<<endl; } return 0; }
s676704918
p00773
u797636303
1555838836
Python
Python3
py
Runtime Error
0
0
792
def tax(p,x): return p*(100+x)//100 def solve(X, Y, S): max_value=0 #max_valueをdef solveの前に入れるミスをしていて全く進みませんでした。関数の定義の理解が進みました。 for a in range(1,S): for b in range(1,S): sum_value=tax(a,X)+tax(b,X) if sum_value==S: c=tax(a,Y)+tax(b,Y) if c>=max_value: max_value=c if sum_value>S: #bが増加すれば必ずSが増加することを使っていて、なるほどと思いました。 break return max_value while True: X,Y,Z=map(int, input().split()) if X==0: break print(solve(X,Y,Z)) #リダイレクションのやり方がわかりませんでした
s370968530
p00773
u797636303
1555838884
Python
Python3
py
Runtime Error
0
0
484
def tax(p,x): return p*(100+x)//100 def solve(X, Y, S): max_value=0 for a in range(1,S): for b in range(1,S): sum_value=tax(a,X)+tax(b,X) if sum_value==S: c=tax(a,Y)+tax(b,Y) if c>=max_value: max_value=c if sum_value>S:  break return max_value while True: X,Y,Z=map(int, input().split()) if X==0: break print(solve(X,Y,Z))
s735132814
p00773
u797636303
1555838895
Python
Python3
py
Runtime Error
0
0
484
def tax(p,x): return p*(100+x)//100 def solve(X, Y, S): max_value=0 for a in range(1,S): for b in range(1,S): sum_value=tax(a,X)+tax(b,X) if sum_value==S: c=tax(a,Y)+tax(b,Y) if c>=max_value: max_value=c if sum_value>S:  break return max_value while True: X,Y,Z=map(int, input().split()) if X==0: break print(solve(X,Y,Z))
s366521234
p00773
u797636303
1555838998
Python
Python3
py
Runtime Error
0
0
458
def tax(p,x): return p*(100+x)//100 def solve(X, Y, S): max_value=0 for a in range(1,S): for b in range(1,S): sum_value=tax(a,X)+tax(b,X) if sum_value==S: c=tax(a,Y)+tax(b,Y) if c>max_value: max_value=c if sum_value>S:  break return max_value while True: X,Y,Z=map(int, input().split()) if X==0: break
s995147707
p00773
u910909659
1555919113
Python
Python3
py
Runtime Error
0
0
678
def tax(p,x): return p*(100+x) // 100 # 整数除算 def solve(X,Y,S): ans = 0 oldsum = 0 for a in range(1,S): for b in range(1,S-a+1): #税抜き価格a,bの総和はS以下である oldsum = tax(a,X)+tax(b,X) #税制改定前の税込合計額 if oldsum == S: # 新税でのtax(a,Y)+tax(b,Y) について検討 newsum = tax(a,Y)+tax(b,Y) if newsum > ans: ans =newsum if oldsum > S: break # b増加ならばsum増加のため return(ans) while True: X,Y,S = map(int, input().split()) if a == 0: break print(solve(a,b,c))
s910934615
p00773
u910909659
1555919189
Python
Python3
py
Runtime Error
0
0
678
def tax(p,x): return p*(100+x) // 100 # 整数除算 def solve(X,Y,S): ans = 0 oldsum = 0 for a in range(1,S): for b in range(1,S-a+1): #税抜き価格a,bの総和はS以下である oldsum = tax(a,X)+tax(b,X) #税制改定前の税込合計額 if oldsum == S: # 新税でのtax(a,Y)+tax(b,Y) について検討 newsum = tax(a,Y)+tax(b,Y) if newsum > ans: ans =newsum if oldsum > S: break # b増加ならばsum増加のため return(ans) while True: X,Y,S = map(int, input().split()) if a == 0: break print(solve(X,Y,S))
s944730237
p00773
u910909659
1555919235
Python
Python3
py
Runtime Error
0
0
692
def tax(p,x): return p*(100+x) // 100 # 整数除算 def solve(X,Y,S): ans = 0 oldsum = 0 newsum = 0 for a in range(1,S): for b in range(1,S-a+1): #税抜き価格a,bの総和はS以下である oldsum = tax(a,X)+tax(b,X) #税制改定前の税込合計額 if oldsum == S: # 新税でのtax(a,Y)+tax(b,Y) について検討 newsum = tax(a,Y)+tax(b,Y) if newsum > ans: ans =newsum if oldsum > S: break # b増加ならばsum増加のため return ans while True: X,Y,S = map(int, input().split()) if a == 0: break print(solve(X,Y,S))
s243997678
p00773
u637657888
1555919302
Python
Python3
py
Runtime Error
0
0
383
def tax(p,x): return p*(100+x) // 100 def solve(X,Y,S): for a in range(1,S): for b in range(1,S): sum = tax(a,X)+tax(b,X) if sum == S: tax(a,Y)+tax(b,Y) if sum > S: break return best while True: X,Y,S = map(int, input().strip().split('')) if X == 0: break print(solve(X,Y,S))
s029541512
p00773
u637657888
1555919384
Python
Python3
py
Runtime Error
0
0
349
def tax(p,x): return p*(100+x) // 100 def solve(X,Y,S): for a in range(1,S): for b in range(1,S): sum = tax(a,X)+tax(b,X) if sum == S: if sum > S: break return best while True: X,Y,S = map(int, input().strip().split('')) if X == 0: break print(solve(X,Y,S))
s711294850
p00773
u637657888
1555919586
Python
Python3
py
Runtime Error
0
0
349
def tax(p,x): return p*(100+x) // 100 def solve(X,Y,S): for a in range(1,S): for b in range(1,S): sum = tax(a,X)+tax(b,X) if sum == S: if sum > S: break return best while True: X,Y,S = map(int, input().strip().split('')) if X == 0: break print(solve(X,Y,S))
s056856130
p00773
u637657888
1555919993
Python
Python3
py
Runtime Error
0
0
413
def tax(p,x): return p*(100+x) // 100 def solve(X,Y,S): for a in range(1,S): for b in range(1,S-a+1): sum = tax(a,X)+tax(b,X) if sum == S: NS = tax(a,Y)+tax(b,Y) A=NS if sum > S: break return A while True: X,Y,S = map(int, input().strip().split('')) if X == 0: break print(solve(X,Y,S))
s525026840
p00773
u637657888
1555920567
Python
Python3
py
Runtime Error
0
0
442
def tax(p,x): return p*(100+x) // 100 def solve(X,Y,S): for a in range(1,S): for b in range(1,S-a+1): sum = tax(a,X)+tax(b,X) if sum == S: NS = tax(a,Y)+tax(b,Y) if newsum > ans: A = NS if sum > S: break return A while True: X,Y,S = map(int, input().split()) if X == 0: break print(solve(X,Y,S))
s408469688
p00773
u637657888
1555920685
Python
Python3
py
Runtime Error
0
0
436
def tax(p,x): return p*(100+x) // 100 def solve(X,Y,S): for a in range(1,S): for b in range(1,S-a+1): sum = tax(a,X)+tax(b,X) if sum == S: NS = tax(a,Y)+tax(b,Y) if NS > A: A = NS if sum > S: break return A while True: X,Y,S = map(int, input().split()) if X == 0: break print(solve(X,Y,S))
s122396275
p00773
u621997536
1420893894
Python
Python3
py
Runtime Error
19920
6748
355
eps = 0.00000001 while True: x, y, s = map(int, input().split()) if x == 0: break x /= 100 y /= 100 n = 0 for a in range(1, s): for b in range(1, s): if (int)(a * (1 + x) + eps) + (int)(b * (1 + x) + eps) == s: n = max(n, (int)(a * (1 + y) + eps) + (int)(b * (1 + y) + eps)) print(n)
s795438778
p00773
u621997536
1420894636
Python
Python
py
Runtime Error
19930
4276
363
eps = 0.00000001 while True: x, y, s = map(int, raw_input().split()) if x == 0: break x /= 100.0 y /= 100.0 n = 0 for a in range(1, s): for b in range(1, s): if (int)(a * (1 + x) + eps) + (int)(b * (1 + x) + eps) == s: n = max(n, (int)(a * (1 + y) + eps) + (int)(b * (1 + y) + eps)) print(n)
s986459224
p00773
u124909914
1426055421
Python
Python3
py
Runtime Error
19930
6808
845
from math import ceil, floor def tax(a, t): return floor(a * (100 + t) / 100) def tax_sum(a, b, t): return tax(a, t) + tax(b, t) while True: x, y, s = map(int, input().split()) if x == 0: break ls = [] for i in range(s): j = i while tax_sum(i,j,x) <= s: if tax_sum(i,j,x) == s: ls.append((i,j)) j += 1 ans = 0 for c in ls: ans = max(ans, tax_sum(c[0], c[1], y)) print(ans) # ls = [i + 1 for i in range(s) if tax(i,x) < s] # ans = 0 # for i in ls: # j = max(ls) - i # # print(i,j,tax(i, y) + tax(j, y)) # ans = max(ans, tax(i, y) + tax(j, y)) # # print(ans) # # org = ceil(s * (100 - x) / 100) # print(org) # # for i in range(ceil(org / 2)): # j = org - i # print(tax(i, y) + tax(j, y))
s658939371
p00773
u124909914
1426055640
Python
Python3
py
Runtime Error
19930
6808
420
from math import floor def tax(a, t): return floor(a * (100 + t) / 100) def tax_sum(a, b, t): return tax(a, t) + tax(b, t) while True: x, y, s = map(int, input().split()) if x == 0: break ls = [] ans = 0 for i in range(s): j = i while tax_sum(i,j,x) <= s: if tax_sum(i,j,x) == s: ans = max(ans, tax_sum(i,j,y)) j += 1 print(ans)
s422704283
p00773
u124909914
1426056191
Python
Python3
py
Runtime Error
19920
6724
394
def tax(a, t): return int(a * (100 + t) / 100) def tax_sum(a, b, t): return tax(a, t) + tax(b, t) while True: x, y, s = map(int, input().split()) if x == 0: break ls = [] ans = 0 for i in range(s): j = i while tax_sum(i,j,x) <= s: if tax_sum(i,j,x) == s: ans = max(ans, tax_sum(i,j,y)) j += 1 print(ans)
s174970400
p00773
u124909914
1426056722
Python
Python3
py
Runtime Error
19930
6724
357
def tax(a, t): return int(a * (100 + t) / 100) def tax_sum(a, b, t): return tax(a, t) + tax(b, t) while True: x, y, s = map(int, input().split()) if x == 0: break ls = [] ans = 0 for i in range(1,s): for j in range(i,s): if tax_sum(i,j,x) == s: ans = max(ans, tax_sum(i,j,y)) print(ans)
s555907040
p00773
u124909914
1426057063
Python
Python3
py
Runtime Error
19920
6724
423
def tax(a, t): return int(a * (100 + t) / 100) def tax_sum(a, b, t): return tax(a, t) + tax(b, t) if __name__ == "__main__": while True: x, y, s = map(int, input().split()) if x == 0: break ls = [] ans = 0 for i in range(1,s): for j in range(i,s): if tax_sum(i,j,x) == s: ans = max(ans, tax_sum(i,j,y)) print(ans)
s421211084
p00773
u124909914
1426057673
Python
Python3
py
Runtime Error
19930
6724
352
def tax(a, t): return int(a * (100 + t) / 100) def tax_sum(a, b, t): return tax(a, t) + tax(b, t) while True: x, y, s = map(int, input().split()) if x == 0: break ans = 0 for i in range(1,s): for j in range(i,s): if tax_sum(i,j,x) == s: ans = max(ans, tax_sum(i,j,y)) print(ans)
s925810176
p00773
u124909914
1426057737
Python
Python3
py
Runtime Error
19920
6724
352
def tax(a, t): return int(a * (100 + t) / 100) def tax_sum(a, b, t): return tax(a, t) + tax(b, t) while True: x, y, s = map(int, input().split()) if x == 0: break ans = 0 for i in range(1,s): for j in range(i,s): if tax_sum(i,j,x) == s: ans = max(ans, tax_sum(i,j,y)) print(ans)
s042996151
p00773
u408260374
1429526932
Python
Python3
py
Runtime Error
19920
6724
346
def calRate(m, r): return int(m * (100 + r) / 100) while True: x, y, s = map(int, input().split()) if x == 0 and y == 0 and s == 0: break ans = 0 for i in range(1, s): for j in range(1, s): if calRate(i, x) + calRate(j, x) == s: ans = max(ans, calRate(i, y) + calRate(j, y)) print(ans)
s374845534
p00773
u316268279
1429550059
Python
Python3
py
Runtime Error
19930
6720
336
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: x,y,s = map(int,input().split()) if (x,y,s) == (0,0,0): break ans = 0 for i in range(1,s-1): for j in range(1,s-1): if i*(100+x)//100 + j*(100+x)//100== s: ans = max(ans,i*(100+y)//100 + j*(100+y)//100) print(ans)
s804781368
p00773
u998188826
1443288690
Python
Python3
py
Runtime Error
40000
7564
270
def tax(p, x): return p * (100 + x) // 100 while True: x, y, s = map(int, input().split()) if (x, y, s) == (0, 0, 0): break r = 0 for i in range(1, s): for j in range(1, s): if (tax(i, x) + tax(j, x)) == s: r = max((tax(i, y) + tax(j, y)), r) print(r)
s080929622
p00773
u871745100
1489132193
Python
Python3
py
Runtime Error
40000
7560
332
g = lambda rate, price: price * (100 + rate) // 100 while True: x, y, s = map(int, input().split()) if x == y == s == 0: break maximum = -1 for i in range(1, s): for j in range(1, s): if g(x, i) + g(x, j) == s: maximum = max(maximum, g(y, i) + g(y, j)) print(maximum)
s481380875
p00773
u371539389
1494232927
Python
Python3
py
Runtime Error
40000
7572
353
import sys def tax(p,x): return int(p*(100+x)/100) while True: x,y,s=[int(i) for i in input().split(" ")] if x==0 and y==0 and s==0: sys.exit() maximum=0 for i in range(1,s-1): for j in range(1,s-1): if tax(i,x)+tax(j,x)==s: maximum=max(tax(i,y)+tax(j,y),maximum) print(maximum)
s073552776
p00773
u283315132
1499330360
Python
Python3
py
Runtime Error
40000
7824
418
import math def ri(): return int(input()) def rli(): return list(map(int, input().split())) def tax(p, rate): return math.floor(p*(100+rate)/100) ans = 0 x, y, s = rli() while(x != 0 or y != 0 or s != 0): for i in range(1,1000): for j in range(1,1000): if(tax(i, x) + tax(j, x) == s): ans = max(ans, tax(i, y) + tax(j, y)) print(ans) ans = 0 x, y, s = rli()
s562376340
p00773
u633333374
1502695648
Python
Python3
py
Runtime Error
0
0
661
import math while 1: x, y, s = map(int,raw_input().split()) if x == y == s == 0: break list = [] for i in range(1,s/2+1): a = i*1.0*100/(100+x) if isinstance(a,int) == False: if (math.trunc(a) + 1)*(100+x)/100 != i: a = 0 else: a = math.trunc(a) + 1 b = (s-i)*1.0*100/(100+x) if isinstance(b,int) == False: if (math.trunc(b) + 1)*(100+x)/100 != s-i: b = 0 else: b = math.trunc(b) + 1 list.append(math.trunc(a*(100+y)/100)+math.trunc(b*(100+y)/100)) print int(math.trunc(max(list)))
s233417177
p00773
u741801763
1506255942
Python
Python3
py
Runtime Error
40000
7736
515
if __name__ == "__main__": while 1: x,y,z = list(map(int,input().strip().split())) if x ==0 and y ==0 and z ==0:break data = [] for i in range(1,z): t1 = i + int(i * x/100) for j in range(1,z): t2 = j + int(j * (x/100)) if t1 + t2 == z:data.append([i,j]) ans = 0 for k in data: temp = k[0] + int(k[0]* (y/100)) + k[1] + int(k[1]* y/100) if temp > ans: ans = temp print(ans)
s545484055
p00773
u015553205
1506943579
Python
Python3
py
Runtime Error
40000
7684
780
#Name: Hidemi_Nakamura #Seat: ???????????????????????? #URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1192&lang=jp #Problem_Title: Tax_Rate_Changed #Impression&Review: ????????????????????????????????????????????????????????????????????????????????? #Taxed = int(p*(1+x/100)) flg = 1 d = [0] while flg > 0: inp = input().split() d.append(inp) flg = int((inp[0]))**2+int((inp[1]))**2+int((inp[2]))**2 for i in range(1,len(d)-1): x = int(d[i][0]) y = int(d[i][1]) s = int(d[i][2]) M = 0 for j in range(1,s-1): for k in range(1,s-1): for l in range(1,s-1): a = int(k*(1+x/100)) b = int(l*(1+x/100)) if (a+b) == s: M = max(M,(a+b)) print(M)
s038751064
p00773
u015553205
1506943818
Python
Python3
py
Runtime Error
40000
7688
729
#Name: Hidemi_Nakamura #Seat: ???????????????????????? #URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1192&lang=jp #Problem_Title: Tax_Rate_Changed #Impression&Review: ????????????????????????????????????????????????????????????????????????????????? #Taxed = int(p*(1+x/100)) flg = 1 d = [0] while flg > 0: inp = input().split() d.append(inp) flg = int((inp[0]))**2+int((inp[1]))**2+int((inp[2]))**2 for i in range(1,len(d)-1): x = int(d[i][0]) y = int(d[i][1]) s = int(d[i][2]) M = 0 for k in range(1,s-1): for l in range(1,s-1): a = int(k*(1+x/100)) b = int(l*(1+x/100)) if (a+b) == s: M = max(M,(a+b)) print(M)
s724751019
p00773
u015553205
1507390371
Python
Python3
py
Runtime Error
40000
7768
490
flg = 1 d = [0] while flg > 0: inp = input().split() d.append(inp) flg = int((inp[0]))**2+int((inp[1]))**2+int((inp[2]))**2 for i in range(1,len(d)-1): x = int(d[i][0]) y = int(d[i][1]) s = int(d[i][2]) M = 0 for k in range(1,s-1): for l in range(1,s-1): a = int(k*(1+x/100)) b = int(l*(1+x/100)) if (a+b) == s: M_ = int(k*(1+y/100)) + int(l*(1+y/100)) M = max(M,M_) print(M)
s372978089
p00773
u015553205
1507390871
Python
Python3
py
Runtime Error
40000
7660
438
flg = 1 while flg > 0: inp = input().split() x = int(inp[0]) y = int(inp[1]) s = int(inp[2]) flg = x**2+y**2+s**2 if flg == 0: break M = 0 for i in range(1,s-1): for j in range(1,s-1): a = int(i*(1+x/100)) b = int(j*(1+x/100)) if (a+b) == s: M_temp = int(i*(1+y/100)) + int(j*(1+y/100)) M = max(M,M_temp) print(M)