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
s140261347
p02315
u494314211
1479020707
Python
Python3
py
Runtime Error
0
0
339
l=[] n,W=list(map(int,input().split())) for i in range(n): item=list(map(int,input().split)) l.append([item[1],item[0]]) # n=4 # l=[[2,3],[1,2],[3,4],[2,2]] #w,v # W=5 print(l) def solve(i,w): if i==n or w<0: return(0) elif w-l[i][0]<0: return(0) else: return(max(solve(i+1,w),l[i][1]+solve(i+1,w-l[i][0]))) print(solve(0,W))
s974167506
p02315
u494314211
1479021064
Python
Python3
py
Runtime Error
0
0
339
l=[] n,W=list(map(int,input().split())) for i in range(n): item=list(map(int,input().split)) l.append([item[1],item[0]]) # n=4 # l=[[2,3],[1,2],[3,4],[2,2]] #w,v # W=5 print(l) def solve(i,w): if i==n or w<0: return(0) elif w-l[i][0]<0: return(0) else: return(max(solve(i+1,w),l[i][1]+solve(i+1,w-l[i][0]))) print(solve(0,W))
s792593372
p02315
u494314211
1479021929
Python
Python3
py
Runtime Error
0
0
390
l=[] n,W=list(map(int,input().split())) for i in range(n): item=list(map(int,input().split)) l.append([item[1],item[0]]) # n=4 # l=[[2,3],[1,2],[3,4],[2,2]] #w,v # W=5 print(l) def solve(i,w): if i==n: return(0) elif w-l[i][0]<0: return(0) else: a=solve(i+1,w) b=l[i][1]+solve(i+1,w-l[i][0]) if b>a: print("select",i) return(b) else: return(a) print(solve(0,W))
s279351420
p02315
u494314211
1479021975
Python
Python3
py
Runtime Error
0
0
393
l=[] n,W=input().split() n=int(n) W=int(W) for i in range(n): item=list(map(int,input().split)) l.append([item[1],item[0]]) # n=4 # l=[[2,3],[1,2],[3,4],[2,2]] #w,v # W=5 print(l) def solve(i,w): if i==n: return(0) elif w-l[i][0]<0: return(0) else: a=solve(i+1,w) b=l[i][1]+solve(i+1,w-l[i][0]) if b>a: print("select",i) return(b) else: return(a) print(solve(0,W))
s341078393
p02315
u494314211
1479022059
Python
Python3
py
Runtime Error
0
0
384
l=[] n,W=input().split() n=int(n) W=int(W) for i in range(n): item=list(map(int,input().split)) l.append([item[1],item[0]]) # n=4 # l=[[2,3],[1,2],[3,4],[2,2]] #w,v # W=5 def solve(i,w): if i==n: return(0) elif w-l[i][0]<0: return(0) else: a=solve(i+1,w) b=l[i][1]+solve(i+1,w-l[i][0]) if b>a: print("select",i) return(b) else: return(a) print(solve(0,W))
s550261908
p02315
u494314211
1479022099
Python
Python3
py
Runtime Error
0
0
363
l=[] n,W=input().split() n=int(n) W=int(W) for i in range(n): item=list(map(int,input().split)) l.append([item[1],item[0]]) # n=4 # l=[[2,3],[1,2],[3,4],[2,2]] #w,v # W=5 def solve(i,w): if i==n: return(0) elif w-l[i][0]<0: return(0) else: a=solve(i+1,w) b=l[i][1]+solve(i+1,w-l[i][0]) if b>a: return(b) else: return(a) print(solve(0,W))
s709334575
p02315
u494314211
1479022925
Python
Python3
py
Runtime Error
0
0
458
l=[] n,W=input().split() n=int(n) W=int(W) for i in range(n): item=list(map(int,input().split())) l.append([item[1],item[0]]) dp=[[False for j in range(W)] for i in range(n)] def solve(i,w): if dp[i][w]==False: if i==n: res=(0) elif w-l[i][0]<0: res=(solve(i+1,w)) else: a=solve(i+1,w) b=l[i][1]+solve(i+1,w-l[i][0]) if b>a: res=(b) else: res=(a) dp[i][w]=res return(res) else: return(dp[i][w]) print(solve(0,W))
s233729152
p02315
u494314211
1479023247
Python
Python3
py
Runtime Error
0
0
458
l=[] n,W=input().split() n=int(n) W=int(W) for i in range(n): item=list(map(int,input().split())) l.append([item[1],item[0]]) dp=[[False for j in range(n)] for i in range(W)] def solve(i,w): if dp[i][w]==False: if i==n: res=(0) elif w-l[i][0]<0: res=(solve(i+1,w)) else: a=solve(i+1,w) b=l[i][1]+solve(i+1,w-l[i][0]) if b>a: res=(b) else: res=(a) dp[i][w]=res return(res) else: return(dp[i][w]) print(solve(0,W))
s430514171
p02315
u494314211
1479023370
Python
Python3
py
Runtime Error
0
0
469
l=[] n,W=input().split() n=int(n) W=int(W) for i in range(n): item=list(map(int,input().split())) l.append([item[1],item[0]]) dp=[[False for j in range(W)+1] for i in range(n)] print(dp) def solve(i,w): if dp[i][w]==False: if i==n: res=(0) elif w-l[i][0]<0: res=(solve(i+1,w)) else: a=solve(i+1,w) b=l[i][1]+solve(i+1,w-l[i][0]) if b>a: res=(b) else: res=(a) dp[i][w]=res return(res) else: return(dp[i][w]) print(solve(0,W))
s264211584
p02315
u843404779
1493780260
Python
Python3
py
Runtime Error
0
0
563
import numpy as np N, W = list(map(int, input().split())) v_list = list() w_list = list() for _ in range(N): v, w = list(map(int, input().split())) v_list.append(v) w_list.append(w) sum_v_table = np.zeros([N+1, W+1], int) for i in range(1, N+1): item = v_list[i-1], w_list[i-1] for w in range(1, W+1): if item[1] > w: sum_v_table[i, w] = sum_v_table[i-1, w] continue sum_v_table[i, w] = max(sum_v_table[i-1, w], sum_v_table[i-1, w-item[1]] + item[0]) max_sum_v = sum_v_table[N, W] print(max_sum_v)
s892831055
p02315
u837811962
1497161551
Python
Python3
py
Runtime Error
0
0
332
N,W = map(int,input().split()) v = [0]*N;w = [0]*N for i in range(N): v[i],w[i] = map(int,input().split()) value = [0 for i in range(W+1)] for i in range(N): for j in range(W+1,-1,-1): if j<w[i]: value[j] = value[j] else: value[j] = max(value[j],value[j-w[i]]+v[i]) print(value[W])
s364917740
p02315
u321712183
1497362933
Python
Python3
py
Runtime Error
0
0
297
N, W = map(int, raw_input().split()) v = [0] * N w = [0] * N for i in range(N): v[i], w[i] = map(int, raw_input().split()) def rec(i, j): if i == N: res = 0 elif j < w[i]: res = rec(i + 1, j) else: res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]) return res print(rec(0, W)) [/sourcecode]
s336174681
p02315
u321712183
1497362954
Python
Python
py
Runtime Error
0
0
297
N, W = map(int, raw_input().split()) v = [0] * N w = [0] * N for i in range(N): v[i], w[i] = map(int, raw_input().split()) def rec(i, j): if i == N: res = 0 elif j < w[i]: res = rec(i + 1, j) else: res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]) return res print(rec(0, W)) [/sourcecode]
s808652372
p02315
u321712183
1507495641
Python
Python3
py
Runtime Error
0
0
360
N, W = map(int,input().split()) v = [0] * N w = [0] * N dp = [[0 for i in range(W + 1)] for j in range(N + 1)] for i in range(N): v[i], w[i] = map(int, raw_input().split()) for i in range(N - 1, -1, -1): for j in range(W + 1): if j < w[i]: dp[i][j] = dp[i + 1][j] else: dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]) print(dp[0][W])
s172499247
p02315
u379644729
1509361450
Python
Python3
py
Runtime Error
0
0
469
N, W = map(int, input().split(" ")) ??? v = [0] * N w = [0] * N dp = [[-1 for i in range(W + 1)] for j in range(N + 1)] ??? for i in range(N): v[i], w[i] = map(int, input().split(" ")) ??? def rec(i, j): if dp[i][j] != -1: return dp[i][j] ??? if i == N: res = 0 elif j < w[i]: res = rec(i + 1, j) else: res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]) dp[i][j] = res return res print(rec(0, W))
s748750038
p02315
u379644729
1509361499
Python
Python3
py
Runtime Error
0
0
469
N, W = map(int, input().split(" ")) ??? v = [0] * N w = [0] * N dp = [[-1 for i in range(W + 1)] for j in range(N + 1)] ??? for i in range(N): v[i], w[i] = map(int, input().split(" ")) ??? def rec(i, j): if dp[i][j] != -1: return dp[i][j] ??? if i == N: res = 0 elif j < w[i]: res = rec(i + 1, j) else: res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]) dp[i][j] = res return res print(rec(0, W))
s241311528
p02315
u957470671
1513615208
Python
Python3
py
Runtime Error
0
0
298
# 0-1 Knapsack Problem N, W = [int(x) for x in input().split()] items = [] for i in range(N): items.append(tuple(int(x) for x in input().split())) DP = [0] * (W+1) for i in range(N): v, w = items[i] for j in range(W, w-1, -1): DP[j] = max(DP[j], v + DP[j-w]) print(DP[-1][-1])
s492925295
p02315
u904185678
1514390375
Python
Python3
py
Runtime Error
0
0
1157
import copy def main(): [N,W]=input().split(" ")'''read from keyboard and put all the item to box''' N=int(N) W=int(W) box=[] for i in range(N): [vi,wi]=input().split(" ") box.append([float(vi),float(wi)]) assemblebox=[]'''creat a set of full permutation of input. using recursion''' assemblebox=permutations(N,box,assemblebox,[]) maximum=0'''optimization''' for i in range(len(assemblebox)): weight=0 value=0 for j in range(N): weight=weight+assemblebox[i][j][1] if(weight>W): break value=value+assemblebox[i][j][0] if(maximum<value): maximum=value print(maximum)'''output''' return 0 def permutations(N,box,assemblebox,record): for i in range(N): Np=N boxp=copy.deepcopy(box) recordp=copy.deepcopy(record) recordp.append(box[i]) boxp.pop(i) Np=Np-1 if(Np==0): assemblebox.append(recordp) else: result=permutations(Np,boxp,assemblebox,recordp) return assemblebox main()
s090088736
p02315
u904185678
1514390429
Python
Python3
py
Runtime Error
0
0
1162
import copy def main(): [N,W]=input().split(" ")'''read from keyboard and put all the item to box''' N=int(N) W=int(W) box=[] for i in range(N): [vi,wi]=input().split(" ") box.append([float(vi),float(wi)]) assemblebox=[]'''creat a set of full permutation of input. using recursion''' assemblebox=permutations(N,box,assemblebox,[]) maximum=0'''optimization''' for i in range(len(assemblebox)): weight=0 value=0 for j in range(N): weight=weight+assemblebox[i][j][1] if(weight>W): break value=value+assemblebox[i][j][0] if(maximum<value): maximum=value print(int(maximum))'''output''' return 0 def permutations(N,box,assemblebox,record): for i in range(N): Np=N boxp=copy.deepcopy(box) recordp=copy.deepcopy(record) recordp.append(box[i]) boxp.pop(i) Np=Np-1 if(Np==0): assemblebox.append(recordp) else: result=permutations(Np,boxp,assemblebox,recordp) return assemblebox main()
s696336271
p02315
u904185678
1514390461
Python
Python
py
Runtime Error
0
0
1162
import copy def main(): [N,W]=input().split(" ")'''read from keyboard and put all the item to box''' N=int(N) W=int(W) box=[] for i in range(N): [vi,wi]=input().split(" ") box.append([float(vi),float(wi)]) assemblebox=[]'''creat a set of full permutation of input. using recursion''' assemblebox=permutations(N,box,assemblebox,[]) maximum=0'''optimization''' for i in range(len(assemblebox)): weight=0 value=0 for j in range(N): weight=weight+assemblebox[i][j][1] if(weight>W): break value=value+assemblebox[i][j][0] if(maximum<value): maximum=value print(int(maximum))'''output''' return 0 def permutations(N,box,assemblebox,record): for i in range(N): Np=N boxp=copy.deepcopy(box) recordp=copy.deepcopy(record) recordp.append(box[i]) boxp.pop(i) Np=Np-1 if(Np==0): assemblebox.append(recordp) else: result=permutations(Np,boxp,assemblebox,recordp) return assemblebox main()
s385050623
p02315
u904185678
1514390542
Python
Python
py
Runtime Error
0
0
1177
import copy def main(): [N,W]=input().split(" ") '''read from keyboard and put all the item to box''' N=int(N) W=int(W) box=[] for i in range(N): [vi,wi]=input().split(" ") box.append([float(vi),float(wi)]) assemblebox=[] '''creat a set of full permutation of input. using recursion''' assemblebox=permutations(N,box,assemblebox,[]) maximum=0 '''optimization''' for i in range(len(assemblebox)): weight=0 value=0 for j in range(N): weight=weight+assemblebox[i][j][1] if(weight>W): break value=value+assemblebox[i][j][0] if(maximum<value): maximum=value print(maximum) '''output''' return 0 def permutations(N,box,assemblebox,record): for i in range(N): Np=N boxp=copy.deepcopy(box) recordp=copy.deepcopy(record) recordp.append(box[i]) boxp.pop(i) Np=Np-1 if(Np==0): assemblebox.append(recordp) else: result=permutations(Np,boxp,assemblebox,recordp) return assemblebox main()
s800145658
p02315
u904185678
1514390640
Python
Python
py
Runtime Error
0
0
1012
import copy def main(): [N,W]=input().split(" ") N=int(N) W=int(W) box=[] for i in range(N): [vi,wi]=input().split(" ") box.append([float(vi),float(wi)]) assemblebox=[] assemblebox=permutations(N,box,assemblebox,[]) maximum=0 for i in range(len(assemblebox)): weight=0 value=0 for j in range(N): weight=weight+assemblebox[i][j][1] if(weight>W): break value=value+assemblebox[i][j][0] if(maximum<value): maximum=value print(maximum) return 0 def permutations(N,box,assemblebox,record): for i in range(N): Np=N boxp=copy.deepcopy(box) recordp=copy.deepcopy(record) recordp.append(box[i]) boxp.pop(i) Np=Np-1 if(Np==0): assemblebox.append(recordp) else: result=permutations(Np,boxp,assemblebox,recordp) return assemblebox main()
s261589057
p02315
u904185678
1514390723
Python
Python
py
Runtime Error
0
0
1000
def main(): [N,W]=input().split(" ") N=int(N) W=int(W) box=[] for i in range(N): [vi,wi]=input().split(" ") box.append([float(vi),float(wi)]) assemblebox=[] assemblebox=permutations(N,box,assemblebox,[]) maximum=0 for i in range(len(assemblebox)): weight=0 value=0 for j in range(N): weight=weight+assemblebox[i][j][1] if(weight>W): break value=value+assemblebox[i][j][0] if(maximum<value): maximum=value print(maximum) return 0 def permutations(N,box,assemblebox,record): for i in range(N): Np=N boxp=copy.deepcopy(box) recordp=copy.deepcopy(record) recordp.append(box[i]) boxp.pop(i) Np=Np-1 if(Np==0): assemblebox.append(recordp) else: result=permutations(Np,boxp,assemblebox,recordp) return assemblebox main()
s682150411
p02315
u904185678
1514402349
Python
Python3
py
Runtime Error
0
0
709
import numpy as np def main(): [N,W]=input().split(" ") N=int(N) W=int(W) inputset=[] for i in range(N): [vi,wi]=input().split(" ") inputset.append([int(vi),int(wi)]) graph=np.zeros([N+1,W+1]) for i in range(N): for j in range(W+1): if(inputset[i][1]>j): graph[i+1,j]=graph[i,j] else: rest=j-inputset[i][1] choosevalue=graph[i,rest]+inputset[i][0] nonchoosevalue=graph[i,j] if(choosevalue>nonchoosevalue): graph[i+1,j]=choosevalue else: graph[i+1,j]=nonchoosevalue print(graph[N,W]) main()
s608278354
p02315
u904185678
1514402382
Python
Python3
py
Runtime Error
0
0
701
import numpy as np def main(): [N,W]=input().split(" ") N=int(N) W=int(W) inputset=[] for i in range(N): [vi,wi]=input().split(" ") inputset.append([int(vi),int(wi)]) graph=np.zeros([N+1,W+1]) for i in range(N): for j in range(W+1): if(inputset[i][1]>j): graph[i+1,j]=graph[i,j] else: rest=j-inputset[i][1] choosevalue=graph[i,rest]+inputset[i][0] nonchoosevalue=graph[i,j] if(choosevalue>nonchoosevalue): graph[i+1,j]=choosevalue else: graph[i+1,j]=nonchoosevalue print(13) main()
s641968176
p02315
u904185678
1514402397
Python
Python3
py
Runtime Error
0
0
707
import numpy as np def main(): [N,W]=input().split(" ") N=int(N) W=int(W) inputset=[] for i in range(N): [vi,wi]=input().split(" ") inputset.append([int(vi),int(wi)]) graph=np.zeros([N+1,W+1]) '''for i in range(N): for j in range(W+1): if(inputset[i][1]>j): graph[i+1,j]=graph[i,j] else: rest=j-inputset[i][1] choosevalue=graph[i,rest]+inputset[i][0] nonchoosevalue=graph[i,j] if(choosevalue>nonchoosevalue): graph[i+1,j]=choosevalue else: graph[i+1,j]=nonchoosevalue''' print(13) main()
s854739084
p02315
u904185678
1514402425
Python
Python3
py
Runtime Error
0
0
226
import numpy as np def main(): [N,W]=input().split(" ") N=int(N) W=int(W) inputset=[] for i in range(N): [vi,wi]=input().split(" ") inputset.append([int(vi),int(wi)]) print(13) main()
s104035012
p02315
u904185678
1514402439
Python
Python3
py
Runtime Error
0
0
55
import numpy as np def main(): print(13) main()
s081132571
p02315
u904185678
1514402497
Python
Python3
py
Runtime Error
0
0
691
def main(): [N,W]=input().split(" ") N=int(N) W=int(W) inputset=[] for i in range(N): [vi,wi]=input().split(" ") inputset.append([int(vi),int(wi)]) graph=np.zeros([N+1,W+1]) for i in range(N): for j in range(W+1): if(inputset[i][1]>j): graph[i+1,j]=graph[i,j] else: rest=j-inputset[i][1] choosevalue=graph[i,rest]+inputset[i][0] nonchoosevalue=graph[i,j] if(choosevalue>nonchoosevalue): graph[i+1,j]=choosevalue else: graph[i+1,j]=nonchoosevalue print(graph[N,W]) main()
s977901656
p02315
u904185678
1514402539
Python
Python3
py
Runtime Error
0
0
54
import numpy as np def main(): print(13) main()
s733530168
p02315
u904185678
1514402559
Python
Python3
py
Runtime Error
0
0
48
import numpy def main(): print(13) main()
s275917620
p02315
u904185678
1514402587
Python
Python3
py
Runtime Error
0
0
48
import numpy def main(): print(13) main()
s351110222
p02315
u904185678
1514402613
Python
Python3
py
Runtime Error
0
0
48
import scipy def main(): print(13) main()
s409780748
p02315
u996738299
1518505108
Python
Python3
py
Runtime Error
0
0
466
N,W = map(int,input().split()) val = [] wei = [] for i in range(N): a,b = map(int,input().split()) val.append(a) wei.append(b) import numpy as np #DPテーブル dp = np.zeros((N+1,W+1)) #初期化 for j in range(W+1): dp[0][j] = 0 #DP計算 for i in range(N): for w in range(W+1): if(w >= wei[i]): dp[i+1][w] = max(dp[i][w - wei[i]] + val[i],dp[i][w]) else: dp[i+1][w] = dp[i][w] print(int(dp[N][W]))
s407974383
p02315
u834139744
1521905569
Python
Python3
py
Runtime Error
0
0
409
N, W = map(int, input().split()) dp = [[0] * W for _ in range(N+1)] weights = list() values = list() for _ in range(N): w, v = map(int, input().split()) weights.append(w) values.append(v) for i in range(N): for w in range(W): if w >= weights[i]: dp[i+1][w] = max(dp[i][w-weights[i]] + values[i], dp[i][w]) else: dp[i+1][w] = dp[i][w] print(dp[n][W])
s074355856
p02315
u185486509
1523808113
Python
Python3
py
Runtime Error
0
0
463
import numpy as np MAX_N = 100 MAX_W = 10000 dp = np.ones((MAX_N+1, MAX_W+1)) * (-1) def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res n, w = (int(s) for s in input().split()) vw = [tuple(int(s) for s in input().split()) for i in range(n)] print(str(rec(0, w)))
s189992160
p02315
u185486509
1523808343
Python
Python3
py
Runtime Error
0
0
463
import numpy as np MAX_N = 100 MAX_W = 10000 dp = np.ones((MAX_N+1, MAX_W+1)) * (-1) def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res n, w = (int(s) for s in input().split()) vw = [tuple(int(s) for s in input().split()) for i in range(n)] print(str(rec(0, w)))
s700503203
p02315
u185486509
1523808585
Python
Python3
py
Runtime Error
0
0
500
import numpy as np MAX_N = 100 MAX_W = 10000 dp = np.ones((MAX_N+1, MAX_W+1)) * (-1) def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res def solve(): n, w = (int(s) for s in input().split()) vw = [tuple(int(s) for s in input().split()) for i in range(n)] print(str(rec(0, w))) solve()
s515525768
p02315
u185486509
1523809043
Python
Python3
py
Runtime Error
0
0
502
MAX_N = 100 MAX_W = 10000 dp = [[-1 for j in range(MAX_W+1)] for i in range(MAX_N+1)] def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res def solve(): n, w = (int(s) for s in input().split()) vw = [tuple(int(s) for s in input().split()) for i in range(n)] print(str(rec(0, w))) solve()
s269374838
p02315
u185486509
1523810003
Python
Python3
py
Runtime Error
0
0
556
def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res def solve(): n, w = (int(s) for s in input().split()) vw = list(tuple(int(s) for s in input().split()) for i in range(n)) print(str(rec(0, w))) if __name__ == '__main__': MAX_N = 100 MAX_W = 10000 dp = list(list(-1 for j in range(MAX_W+1)) for i in range(MAX_N+1)) solve()
s229338963
p02315
u185486509
1523810226
Python
Python3
py
Runtime Error
0
0
561
def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res def solve(): n, w = tuple(int(s) for s in input().split()) vw = list(tuple(int(s) for s in input().split()) for i in range(n)) print(str(rec(0, w))) if __name__ == '__main__': MAX_N = 100 MAX_W = 10000 dp = list(list(-1 for j in range(MAX_W+1)) for i in range(MAX_N+1)) solve()
s467091653
p02315
u185486509
1523811474
Python
Python3
py
Runtime Error
0
0
602
import sys sys.setrecursionlimit(10000) def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res def solve(): n, w = tuple(int(s) for s in input().split()) vw = list(tuple(int(s) for s in input().split()) for i in range(n)) print(str(rec(0, w))) if __name__ == '__main__': MAX_N = 100 MAX_W = 10000 dp = list(list(-1 for j in range(MAX_W+1)) for i in range(MAX_N+1)) solve()
s484933739
p02315
u185486509
1523811511
Python
Python3
py
Runtime Error
0
0
603
import sys sys.setrecursionlimit(100000) def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res def solve(): n, w = tuple(int(s) for s in input().split()) vw = list(tuple(int(s) for s in input().split()) for i in range(n)) print(str(rec(0, w))) if __name__ == '__main__': MAX_N = 100 MAX_W = 10000 dp = list(list(-1 for j in range(MAX_W+1)) for i in range(MAX_N+1)) solve()
s480967283
p02315
u185486509
1523811613
Python
Python3
py
Runtime Error
0
0
604
import sys sys.setrecursionlimit(100000) def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res def solve(): n, w = tuple(int(s) for s in input().split()) vw = list(tuple(int(s) for s in input().split()) for i in range(n)) print("{}", rec(0, w)) if __name__ == '__main__': MAX_N = 100 MAX_W = 10000 dp = list(list(-1 for j in range(MAX_W+1)) for i in range(MAX_N+1)) solve()
s005568402
p02315
u185486509
1523811713
Python
Python3
py
Runtime Error
0
0
593
import sys sys.setrecursionlimit(100000) MAX_N = 100 MAX_W = 10000 dp = list(list(-1 for j in range(MAX_W+1)) for i in range(MAX_N+1)) def rec(i, j): if dp[i][j] >= 0: return dp[i][j] if i == n: res = 0 elif j < vw[i][1]: res = rec(i+1, j) else: res = max(rec(i+1, j), rec(i+1, j-vw[i][1])+vw[i][0]) dp[i][j] = res return res def solve(): n, w = tuple(int(s) for s in input().split()) vw = list(tuple(int(s) for s in input().split()) for i in range(n)) print("{}", rec(0, w)) if __name__ == '__main__': solve()
s624966778
p02315
u724548524
1525836144
Python
Python3
py
Runtime Error
0
0
1775
import sys def cv(w, p, vi, wi): global value w0 = 0 v0 = 0 for i in range(len(vi)): w0 += wi[i] if w0 >= w:def cv(w, p, vi, wi): global value # print(value) # print("{} {} {} {}".format(w, p, vi, wi)) w0 = 0 v0 = 0 for i in range(len(vi)): w0 += wi[i] if w0 > w: if i == len(vi) -1 or v0 + vi[i + 1] <= value - p: return max(p + v0, value) value = max(value, p + v0) break v0 += vi[i] if len(vi) == 1: value = max(value, p + vi[0] if wi[0] <= w else p) return value elif wi[0] <= w: value = max(value, p + vi[0]) return max(cv(w - wi[0], p + vi[0], vi[1:], wi[1:]), cv(w, p, vi[1:], wi[1:])) else: return cv(w, p, vi[1:], wi[1:]) n, w = map(int, input().split()) c = [] for _ in range(n): c.append(tuple(map(int, input().split()))) c.sort(key = lambda x: x[1]) c.sort(key = lambda x: x[0] / x[1], reverse = True) vi, wi = zip(*c) value = 0 print(cv(w, 0, vi, wi)) if i == len(vi) -1 or v0 + vi[i + 1] <= value - p: return value value = max(value, p + v0) break v0 += vi[i] if len(vi) == 1: value = max(value, p + vi[0] if wi[0] <= w else p) return value elif wi[0] <= w: value = max(value, p + vi[0]) return max(cv(w - wi[0], p + vi[0], vi[1:], wi[1:]), cv(w, p, vi[1:], wi[1:])) else: return cv(w, p, vi[1:], wi[1:]) n, w = map(int, input().split()) c = [] for _ in range(n): c.append(tuple(map(int, input().split()))) c.sort(key = lambda x: x[1]) c.sort(key = lambda x: x[0] / x[1], reverse = True) vi, wi = zip(*c) value = 0 print(cv(w, 0, vi, wi))
s521177080
p02315
u150984829
1525927628
Python
Python3
py
Runtime Error
0
0
155
N,W=map(int,input().split()) C=[0]*-~W for _ in[0]*N: v,w=mpa(int,input().split()) for i in range(W,w-1,-1): t=v+C[i-w] if t>C[i]:C[j]=t print(C[W])
s849331848
p02315
u150984829
1525927644
Python
Python3
py
Runtime Error
0
0
155
N,W=map(int,input().split()) C=[0]*-~W for _ in[0]*N: v,w=map(int,input().split()) for i in range(W,w-1,-1): t=v+C[i-w] if t>C[i]:C[j]=t print(C[W])
s187097400
p02315
u399892098
1526274486
Python
Python3
py
Runtime Error
0
0
458
import numpy as np num_line,max_weight = map(int,input().split()) dp = np.zeros([num_line+1,max_weight+1]) fac = [] for i in range(num_line): v,w = map(int,input().split()) fac.append([v,w]) for i in range(1,num_line + 1): for j in range(1,max_weight+1): if(j >= fac[i-1][1]): dp[i][j] = max(dp[i-1][j-fac[i-1][1]]+fac[i-1][0],dp[i-1][j]) else: dp[i][j] = dp[i-1][j] print(int(dp[num_line][max_weight]))
s197983817
p02315
u121616304
1528293653
Python
Python3
py
Runtime Error
20
5644
419
N,W=map(int,input().split()) items=[] for i in range(N): items.append(list(map(int,input().split()))) dp = [[0 for i in range(100)] for j in range(100)] for i in range(N): dp[i][0]=0 for i in range(N): for w in range(W+1): if w>=items[i][1]: dp[i+1][w]=max(dp[i][w-items[i][1]]+items[i][0],dp[i][w]) else: dp[i+1][w]=dp[i][w] print(dp[N][W])
s935391934
p02315
u121616304
1528293864
Python
Python3
py
Runtime Error
240
18248
420
N,W=map(int,input().split()) items=[] for i in range(N): items.append(list(map(int,input().split()))) dp = [[0 for i in range(10000)] for j in range(100)] for i in range(N): dp[i][0]=0 for i in range(N): for w in range(W+1): if w>=items[i][1]: dp[i+1][w]=max(dp[i][w-items[i][1]]+items[i][0],dp[i][w]) else: dp[i+1][w]=dp[i][w] print(dp[N][W])
s118833630
p02315
u121616304
1528293919
Python
Python3
py
Runtime Error
240
18248
420
N,W=map(int,input().split()) items=[] for i in range(N): items.append(list(map(int,input().split()))) dp = [[0 for i in range(10000)] for j in range(100)] for i in range(N): dp[i][0]=0 for i in range(N): for w in range(W+1): if w>=items[i][1]: dp[i+1][w]=max(dp[i][w-items[i][1]]+items[i][0],dp[i][w]) else: dp[i+1][w]=dp[i][w] print(dp[N][W])
s876774476
p02315
u121616304
1528293926
Python
Python3
py
Runtime Error
550
25336
420
N,W=map(int,input().split()) items=[] for i in range(N): items.append(list(map(int,input().split()))) dp = [[0 for i in range(10001)] for j in range(100)] for i in range(N): dp[i][0]=0 for i in range(N): for w in range(W+1): if w>=items[i][1]: dp[i+1][w]=max(dp[i][w-items[i][1]]+items[i][0],dp[i][w]) else: dp[i+1][w]=dp[i][w] print(dp[N][W])
s377198848
p02315
u138224929
1528445405
Python
Python3
py
Runtime Error
30
6776
758
#問題2 #https://qiita.com/drken/items/a5e6fe22863b7992efdb #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp n, w = map(int,input().split()) value = [] weight = [] for i in range(n): val,wei = map(int,input().split()) value.append(val) weight.append(wei) #dp i <= 110, w <= 1010 dp = [] for i in range(110): o = [0 for i in range(1010)] dp.append(o) #i = 0 何も入れない状態を初期化する for ww in range(w): dp[0][ww] = 0 for i in range(0,n): for ww in range(w+1): #dp[i+1]に最終状態が格納される if ww >= weight[i] : dp[i+1][ww] = max(dp[i][ww-weight[i]] + value[i], dp[i][ww]) else: dp[i+1][ww] = dp[i][ww] print(dp[n][w])
s784605217
p02315
u650712316
1528691008
Python
Python3
py
Runtime Error
20
5600
595
N,W = map(int,input().split()) value = [0] weight = [0] for i in range(N): v,w = map(int,input().split()) value.append(v) weight.append(w) dp = [[0]*(N+10) for _ in range(W+10)] #dp[k][w]はk番目までの荷物を使ってw以内に抑えた時の最大値 #dp[0][_] = dp[_][w] = 0と定義する(荷物は1番目、2番目、・・・、N番目と定義する) for w in range(1,W+2): for k in range(1,N+1): if weight[k] > w: dp[k][w] = dp[k-1][w] else: dp[k][w] = max(dp[k-1][w], value[k] + dp[k-1][w-weight[k]]) print(dp[N][W])
s475012896
p02315
u650712316
1528691034
Python
Python3
py
Runtime Error
20
5604
405
N,W = map(int,input().split()) value = [0] weight = [0] for i in range(N): v,w = map(int,input().split()) value.append(v) weight.append(w) dp = [[0]*(N+10) for _ in range(W+10)] for w in range(1,W+2): for k in range(1,N+1): if weight[k] > w: dp[k][w] = dp[k-1][w] else: dp[k][w] = max(dp[k-1][w], value[k] + dp[k-1][w-weight[k]]) print(dp[N][W])
s678438427
p02315
u955541348
1528713582
Python
Python3
py
Runtime Error
0
0
318
N, W = map(int,input().split()) A = [] B = [[0 for j in range(W)]] for i in range(N): A.append(list(map(int, input().split()))) B.append([0 for j in range(W)]) for i in range(N): for j in range(W): if j >= A[i][1]: B[i + 1][j] = max(B[i][j], B[i][j - A[i][1]] + A[i][0]) print(B[N][W])
s425543425
p02316
u209989098
1532052016
Python
Python3
py
Runtime Error
0
0
182
N,W = map(int, input().split()) dp = [0]*(W+1) for i in range(N): a,b = map(int,input().split()) for j in range(b,W+1,b): x = a + dp[j-b] if x >= dp[j]: dp = x print(W+1)
s621645524
p02316
u209989098
1532052299
Python
Python3
py
Runtime Error
0
0
189
N,W = map(int, input().split()) dp = [0]*(W+1) for i in range(N): a,b = map(int,input().split()) for j in range(b,W+1,b): x = a + dp[j-b] if x >= dp[j]: dp[j] = x print(dp[W+1])
s070427470
p02316
u134812425
1541124542
Python
Python3
py
Runtime Error
0
0
1277
import bisect import collections import heapq import itertools import math import string import sys from itertools import chain, takewhile import numpy as np def read( f, *shape, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace) ): def read_word(): return f("".join(takewhile(lambda c: c not in whitespaces, it)).strip()) if not shape: return read_word() elif len(shape) == 1: return [read_word() for _ in range(shape[0])] elif len(shape) == 2: return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])] def arr(*shape, fill_value=0): if isinstance(shape[0], int): return np.full(shape, fill_value).tolist() return np.full_like(shape[0], fill_value).tolist() def debug(**kwargs): print( ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()), file=sys.stderr, ) def main(): N, W = read(int, 2) values = arr(N) weights = arr(N) for i in range(N): values[i], weights[i] = read(int, 2) dp = arr(W + 1, fill_value=0) for i in range(N): for w in range(weights[i], W + 1): dp[w] = max(dp[w], dp[w - weights[i]] + values[i]) print(dp[W]) if __name__ == "__main__": main()
s834035281
p02316
u567380442
1427804569
Python
Python3
py
Runtime Error
0
0
417
from sys import stdin readline = stdin.readline n, total_wait = map(int, readline().split()) value_wait = [list(map(int, readline().split())) for _ in range(n)] value_wait.sort(key=operator.itemgetter(1), reverse=True) dp = [0] * (total_wait + 1) for ni, (v, w) in enumerate(value_wait): for tw in range(w, total_wait + 1): if dp[tw] < dp[tw - w] + v: dp[tw] = dp[tw - w] + v print(dp[-1])
s030237078
p02316
u551083572
1462626875
Python
Python3
py
Runtime Error
60
8352
732
# coding: utf-8 from __future__ import print_function from __future__ import unicode_literals from __future__ import division from __future__ import absolute_import def array2d(row, col, init = None): return [[init for _ in range(col)] for _ in range(row)] N, W = map(int, input().split(" ")) v = [] w = [] for i in range(N): vi, wi = map(int, input().split(" ")) v.append(vi) w.append(wi) dpt = array2d(N + 1, W + 1) def dp(i, j): if dpt[i][j] is not None: return dpt[i][j] if i == 0: dpt[i][j] = 0 return 0 if j < w[i-1]: dpt[i][j] = dp(i-1, j) return dpt[i][j] dpt[i][j] = max(dp(i-1, j), dp(i, j-w[i-1]) + v[i-1]) return dpt[i][j] print(dp(N, W))
s434765745
p02316
u551083572
1462627000
Python
Python3
py
Runtime Error
20
7732
799
# coding: utf-8 from __future__ import print_function from __future__ import unicode_literals from __future__ import division from __future__ import absolute_import def array2d(row, col, init = None): return [[init for _ in range(col)] for _ in range(row)] N, W = map(int, input().split(" ")) v = [] w = [] for i in range(N): vi, wi = map(int, input().split(" ")) v.append(vi) w.append(wi) dpt = array2d(N + 1, W + 1) def dp(i, j): if dpt[i][j] is not None: return dpt[i][j] if i == 0: dpt[i][j] = 0 return 0 if j < w[i-1]: dpt[i][j] = dp(i-1, j) return dpt[i][j] dpt[i][j] = max(dp(i-1, j), dp(i, j-w[i-1]) + v[i-1]) return dpt[i][j] for i in range(N + 1): for j in range(N + 1): dp(i, j) print(dp(N, W))
s298254063
p02316
u252368621
1482162963
Python
Python3
py
Runtime Error
50
8288
546
def dfs_dp(w,v,n,W,index,dp): if (dp[index][W] != -1): return dp[index][W] if index==n: return 0 if W<w[index]: return dfs_dp(w,v,n,W,index+1,dp) ret=max(dfs_dp(w,v,n,W,index+1,dp),v[index]+dfs_dp(w,v,n,W-w[index],index+1,dp),v[index]+dfs_dp(w,v,n,W-w[index],index,dp)) dp[index][W]=ret return ret a,b=input().split() N,W=int(a),int(b) w=[] v=[] dp=[[-1 for i in range(W+1)] for j in range(N+1)] for i in range(N): a,b=input().split() v.append(int(a)) w.append(int(b)) print(dfs_dp(w,v,N,W,0,dp))
s688476284
p02316
u197615397
1506341860
Python
Python3
py
Runtime Error
0
0
267
N, W = map(int, input().split()) dp = [0] + [-1]*(W+1) for i in range(N): v, w = map(int, input().split()) for j in range(0, W-w+1): if dp[j] > -1 and dp[j+w] < dp[j] + v: dp[j+w] = dp[j] + v print(max(dp))
s922977073
p02316
u938045879
1522657429
Python
Python3
py
Runtime Error
20
5616
638
n,w = map(int, input().split()) values = [0] weights = [0] counter=0 rest = 0 for i in range(n): v,weight = map(int, input().split()) values.append(v) weights.append(weight) dp=[[0 for i in range(w+1)]for j in range(v+1)] for i in range(1, n+1): for j in range(1, w+1): rest = j counter = 0 if(j >= weights[i]): while(rest-weights[i]>=0): counter = counter+1 rest = rest - weights[i] dp[i][j] = max(dp[i][j], dp[i-1][j], dp[i-1][j-weights[i]*counter]+values[i]*counter) else: dp[i][j] = dp[i-1][j] print(dp[n][-1])
s273095605
p02317
u209989098
1532165569
Python
Python3
py
Runtime Error
0
0
204
import bisect a = int(input()) b = [int(input()) in d in range(a)] c = [b[1]] for i in b[1:]: if c[-1] < i: c.append(i) else: c[bisect.bisect_left(c,i)] = i print(len(L))
s772035730
p02317
u209989098
1532165609
Python
Python3
py
Runtime Error
0
0
204
import bisect a = int(input()) b = [int(input()) in d in range(a)] c = [b[1]] for i in b[1:]: if c[-1] < i: c.append(i) else: c[bisect.bisect_left(c,i)] = i print(len(c))
s747185990
p02317
u088372268
1534744578
Python
Python3
py
Runtime Error
20
5640
334
import bisect INF = 1 << 20 def main(): n = int(input()) a = [int(input()) for i in range(n)] dp = [INF for i in range(n+1)] for i in range(1, n+1): idx = bisect.bisect_left(dp, a[i-1]) dp[idx] = a[i-1] ans = bisect.bisect_left(dp, INF) print(ans) if __name__ == '__main__': main()
s869775719
p02317
u467648242
1545837005
Python
Python3
py
Runtime Error
0
0
356
n = int(input()) in_list = [] for i in range(n): in_list.append(list(map(int, input().split()))) matrices = [["0" for _ in range(n)] for _ in range(n)] for i in range(n): inp = in_list[i] u = inp[0] k = inp[1] for j in range(k): m = inp[j+2] matrices[i][m-1] = "1" for i in range(n): print(" ".join(matrices[i]))
s853891152
p02317
u567380442
1427862399
Python
Python3
py
Runtime Error
30
6736
266
from sys import stdin import bisect readline = stdin.readline dp = [-float('inf')] n = int(readline()) a = (int(readline()) for _ in range(n)) for ai in a: if dp[-1] < ai: dp.append(ai) else: dp[bisect.bisect(dp, ai)] = ai print(len(dp) - 1)
s372976869
p02317
u633068244
1432611576
Python
Python
py
Runtime Error
0
0
361
import bisect def lis(A): n = len(A) L = [0] * n L[0] = A[0] length = 1 for i in xrange(1, n): if L[length - 1] < A[i]: L[length] = A[i] length += 1 else: L[bisect.bisect_left(L, A[i])] = A[i] return length n = int(raw_input()) a = [int(raw_input()) for i in xrange(n)] print lis(a)
s987355139
p02317
u260980560
1465193369
Python
Python
py
Runtime Error
10
6444
174
from bisect import * n = input() dp = [n+1]*(n+1) dp[0] = -1 for i in xrange(n): a = input() idx = bisect(dp, a-1) dp[idx] = min(a, dp[idx]) print bisect(dp, n)-1
s728408029
p02317
u797673668
1468909154
Python
Python3
py
Runtime Error
20
7716
158
n = int(input()) array = [int(input()) for _ in range(n)] dp = [0] * (max(array) + 1) for a in array: dp[a] = max(dp[a], max(dp[:a]) + 1) print(max(dp))
s457304514
p02317
u252368621
1482305600
Python
Python3
py
Runtime Error
20
7764
513
def dfs(index,prev,n,a,dp): if dp[index][prev] != -1: return dp[index][prev] if index==n: return 0 if prev != -1 and a[prev]>=a[index]: return dfs(index+1,prev,n,a,dp) ren=max(dfs(index+1,prev,n,a,dp),dfs(index+1,index,n,a,dp)+1) dp[index][prev]=ren return ren n=int(input()) a=[-1 for i in range(n)] for i in range(n): a[i]=int(input()) dp=[[-1 for i in range(n+1)] for j in range(n+1)] sum=dfs(0,-1,n,a,dp) if sum==0: print(1) else: print(sum)
s006762063
p02317
u854976463
1490870676
Python
Python
py
Runtime Error
0
0
530
def _input(n): return [int(raw_input()) if i in xrange(n)] def LIS(arr): arr = [0] + arr L = [0] + [0] * len(arr) P = [-1] + [0] * len(arr) for i in xrange(1, len(arr)): k = 0 for j in xrange(0, i): if arr[j] < arr[i] and L[j] > L[k]: k = j L[i] = L[k] + 1 P[i] = k return max(L) #============================================== def main(): n = int(raw_input()) arr = _input(n) print LIS(arr) if __name__ == "__main__": main()
s525711572
p02317
u603049633
1496884334
Python
Python3
py
Runtime Error
0
0
274
from bisect import bisect_left import sys n = int(input()) A = [int(i.rstrip("\n")) for i in sys.stdin.readlines()] def LIS(): L = A[:1] for i in A[1:]: if L[-1] < i: L.append(i) else: L[j] = i return len(L) print(LIS())
s953329187
p02317
u855199458
1503220044
Python
Python3
py
Runtime Error
20
7596
240
# -*- coding: utf-8 -*- from bisect import bisect N = int(input()) A = [int(input()) for _ in range(N)] L = [A[0]] for i in range(1, N): if L[-1] < A[i]: L.append(A[i]) else: L[bisect(L, A[i])] = A[i] print(len(L))
s629254417
p02317
u011621222
1530153404
Python
Python3
py
Runtime Error
20
5600
436
n = int(input()) parent = [-1]*n def root(x): if parent[x] < 0: return x parent[x] = y = root(parent[x]) return y def union(x, y): px = root(x) py = root(y) if px == py: return if px > py: px = root(y) py = root(x) parent[x] += parent[y] parent[y] = px return Q = [] for i in range(n): a = int(input()) for j in range(i): if Q[-j-1] < a: union(Q[-j-1], a) continue continue Q += [a] print(-min(parent))
s183785957
p02317
u766926358
1530154266
Python
Python3
py
Runtime Error
20
5608
631
n = int(input()) parent = [-1]*n def root(x): if parent[x] < 0: return x parent[x] = y = root(parent[x]) return y def union(x, y): px = root(x) py = root(y) if px == py: return if px > py: px = root(y) py = root(x) parent[x] += parent[y] parent[y] = px return Q = [] for i in range(n): a = int(input()) for j in range(i): if Q[-j-1] < a: union(Q[-j-1], a) continue Q += [a] print(-min(parent)) """ import bisect N = int(input()) A = [int(input()) for _ in range(N)] L = [A[0]] for a in A[1:]: if L[-1] < a: L.append(a) else: L[bisect.bisect_left(L, a)] = a print(len(L)) """
s805278681
p02317
u603577460
1530624650
Python
Python3
py
Runtime Error
0
0
492
#include <bits/stdc++.h> using namespace std; int T; int DS[1001]; int DP[1001][1001]; int f(int i,int backed){ int &s = DP[i][backed]; if(i==T)return s=0; else if(backed!=T && DS[i]<=DS[backed])return s=f(i+1,backed); else return s=max(1+f(i+1,i),f(i+1,backed)); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>T; memset(DP,-1,sizeof(DP)); for(int i=0;i<T;++i){ cin>>DS[i]; } cout<<f(0,T)<<endl; return 0; }
s201328933
p02317
u603577460
1530625584
Python
Python3
py
Runtime Error
0
0
521
#include <bits/stdc++.h> using namespace std; int T; int DS[10001]; int DP[1001][1001]; int f(int i,int backed){ int &s = DP[i][backed]; if(i==T)return s=0; else if(s!=-1)return s; else if(backed!=T && DS[i]<=DS[backed])return s=f(i+1,backed); else return s=max(1+f(i+1,i),f(i+1,backed)); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>T; memset(DP,-1,sizeof(DP)); for(int i=0;i<T;++i){ cin>>DS[i]; } cout<<f(0,T)<<endl; return 0; }
s145733681
p02317
u603577460
1530636977
Python
Python3
py
Runtime Error
0
0
479
#include <bits/stdc++.h> using namespace std; int DP[100001]; int DS[100001]; int T; int LIS(){ int maxan=0; for(int k=0;k<T;k++){ DP[k]=1; for(int i=0;i<k;i++){ if(DS[i]<DS[k])DP[k]=max(DP[k],DP[i]+1); } maxan = max(maxan,DP[k]); } return maxan; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>T; for(int i=0;i<T;i++)cin>>DS[i]; cout<<LIS()<<endl; return 0; }
s314441062
p02318
u609614788
1531371135
Python
Python3
py
Runtime Error
0
0
671
#include <iostream> #include <string> int mini(int x,int y){ if(x<y){ return x; }else{ return y; } } int main() { std::string str1,str2; int A[1001][1001]; int gap; std::cin>>str1; std::cin>>str2; for(int i=0;i<=str1.size();i++){ A[0][i]=i; } for(int i=0;i<=str2.size();i++){ A[i][0]=i; } for(int i=1;i<=str1.size();i++){ for(int j=1;j<=str2.size();j++){ if(str1[i-1]==str2[j-1]){ gap=0; }else{ gap=1; } A[i][j]=mini(A[i-1][j-1]+gap,mini(A[i-1][j]+1,A[i][j-1]+1+1)); //std::cout<<A[i][j]<<" "; } //std::cout<<"\n"; } std::cout<<A[str1.size()][str2.size()]<<"\n"; return 0; }
s862426268
p02318
u609614788
1531373595
Python
Python3
py
Runtime Error
0
0
985
#include <iostream> #include <string> int mini(int x,int y){ if(x<y){ return x; }else{ return y; } } int main() { std::string str1,str2; int A[1001][1001]; int gap; std::cin>>str1; std::cin>>str2; for(int i=0;i<str1.size();i++){ A[i][0]=i; } for(int i=0;i<str2.size();i++){ A[0][i]=i; } /* for(int i=0;i<str1.size();i++){ for(int j=0;j<str2.size();j++){ std::cout<<A[i][j]<<" "; } std::cout<<"\n"; } */ for(int i=1;i<=str1.size();i++){ for(int j=1;j<=str2.size();j++){ if(str1[i-1]==str2[j-1]){ gap=0; }else{ gap=1; } A[i][j]=mini(A[i-1][j-1]+gap,mini(A[i-1][j]+1,A[i][j-1]+1)); //std::cout<<A[i-1][j-1]<<" "; } //std::cout<<"\n"; } if(str1.size()>str2.size()){ A[str1.size()-1][str2.size()-1]+=str1.size()-str2.size(); }else{ A[str1.size()-1][str2.size()-1]+=str2.size()-str1.size(); } std::cout<<A[str1.size()-1][str2.size()-1]<<"\n"; return 0; }
s900701773
p02318
u609614788
1531373751
Python
Python3
py
Runtime Error
0
0
1082
#include <iostream> #include <string> int mini(int x,int y){ if(x<y){ return x; }else{ return y; } } int main() { std::string str1,str2; int A[1001][1001]; int gap; std::cin>>str1; std::cin>>str2; for(int i=0;i<str1.size();i++){ A[i][0]=i; } for(int i=0;i<str2.size();i++){ A[0][i]=i; } /* for(int i=0;i<str1.size();i++){ for(int j=0;j<str2.size();j++){ std::cout<<A[i][j]<<" "; } std::cout<<"\n"; } */ for(int i=1;i<=str1.size();i++){ for(int j=1;j<=str2.size();j++){ if(str1[i-1]==str2[j-1]){ gap=0; }else{ gap=1; } A[i][j]=mini(A[i-1][j-1]+gap,mini(A[i-1][j]+1,A[i][j-1]+1)); //std::cout<<A[i-1][j-1]<<" "; } //std::cout<<"\n"; } if(str1.size()>str2.size()){ A[str1.size()-1][str2.size()-1]+=str1.size()-str2.size(); }else{ A[str1.size()-1][str2.size()-1]+=str2.size()-str1.size(); } if(str1.size()>str2.size()){ std::cout<<A[str1.size()-1][str2.size()-1]<<"\n"; }else{ std::cout<<A[str1.size()][str2.size()]<<"\n"; } return 0; }
s967566198
p02318
u609614788
1531375146
Python
Python3
py
Runtime Error
0
0
1120
#include <iostream> #include <string> int mini(int x,int y){ if(x<y){ return x; }else{ return y; } } int main() { std::string str1,str2; int A[1001][1001]; int gap; std::cin>>str1; std::cin>>str2; for(int i=0;i<=str1.size();i++){ A[i][0]=i; } for(int i=0;i<=str2.size();i++){ A[0][i]=i; } /* for(int i=0;i<str1.size();i++){ for(int j=0;j<str2.size();j++){ std::cout<<A[i][j]<<" "; } std::cout<<"\n"; } */ for(int i=1;i<=str1.size();i++){ for(int j=1;j<=str2.size();j++){ if(str1[i-1]==str2[j-1]){ gap=0; }else{ gap=1; } A[i][j]=mini(A[i-1][j-1]+gap,mini(A[i-1][j]+1,A[i][j-1]+1)); //std::cout<<A[i-1][j-1]<<" "; } //std::cout<<"\n"; } if(str1.size()>str2.size()){ A[str1.size()-1][str2.size()-1]+=str1.size()-str2.size(); }else{ A[str1.size()-1][str2.size()-1]+=str2.size()-str1.size(); } if(str1.size()>str2.size() and A[str1.size()][str2.size()]!=1){ std::cout<<A[str1.size()-1][str2.size()-1]<<"\n"; }else{ std::cout<<A[str1.size()][str2.size()]<<"\n"; } return 0; }
s436071078
p02318
u405027099
1531820476
Python
Python
py
Runtime Error
0
0
503
def levenshtein(X,Y): f=[[0 for i in range(len(Y)+1)]for j in range(len(X)+1)] for i in range(len(X)+1): f[i][0]=i for j in range(1,len(Y)+1): f[0][j]=j for i in range(1,len(X)+1): for j in range(len(Y)+1): if X[i-1]==Y[j-1]: f[i][j]=min(f[i-1][j]+1,f[i][j-1]+1,f[i-1][j-1]) else: f[i][j]=min(f[i-1][j]+1,f[i][j-1]+1,f[i-1][j-1]+1) return f[len(X)][len(Y)] X=input() Y=input() print(levenshtein(X,Y))
s606988860
p02318
u063056051
1531828281
Python
Python3
py
Runtime Error
0
0
465
list1=list(input()) list2=list(input()) cost=0 list_d=[[0 for i in range(len(list2)+1)] for j in range(list1)+1] for i in range(1,len(list1)+1): list_d[i][0]=i for j in range(1,len(list2)+1): list_d[0][j]=j for i in range(1,len(list1)+1): for j in range(1,len(list2)+1): if list1[i-1]!=list2[j-1]: cost=1 else: cost=0 list_d[i][j]=min(list_d[i-1][j-1]+cost,list_d[i-1][j]+1,list_d[i][j-1]+1) print(list_d[len(list1)][len(list2)])
s175532849
p02318
u063056051
1531828331
Python
Python3
py
Runtime Error
0
0
470
list1=list(input()) list2=list(input()) cost=0 list_d=[[0 for i in range(len(list2)+1)] for j in range(len(list1))+1] for i in range(1,len(list1)+1): list_d[i][0]=i for j in range(1,len(list2)+1): list_d[0][j]=j for i in range(1,len(list1)+1): for j in range(1,len(list2)+1): if list1[i-1]!=list2[j-1]: cost=1 else: cost=0 list_d[i][j]=min(list_d[i-1][j-1]+cost,list_d[i-1][j]+1,list_d[i][j-1]+1) print(list_d[len(list1)][len(list2)])
s989739819
p02318
u063056051
1531828636
Python
Python3
py
Runtime Error
0
0
432
list1=list(input()) list2=list(input()) list_d=[[0 for i in range(len(list2)+1)] for j in range(len(list1)+1)] list_d[1][0]=1 list_d[0][1]=1 for i in range(1,len(list1)+1): for j in range(1,len(list2)+1): list_d[i][0]=i list_d[0][j]=j if list1[i-1]!=list2[j-1]: cost=1 else: cost=0 list_d[i][j]=min(list_d[i-1][j-1]+cost,list_d[i-1][j]+1,list_d[i][j-1]+1) print(list_d[len(list1)][len(list2)])
s112977234
p02318
u411881271
1531849394
Python
Python3
py
Runtime Error
0
0
475
n = int(input()) cnt=[0 for i in range(n)] for i in range(n): A = [] A = input() B = [] B = input() DP = [[0 for k in range(len(B)+1)] for j in range(len(A)+1)] for j in range(len(A)+1): DP[j][0]=j for k in range(len(B)+1): DP[0][k]=k for j in range(len(A)): for k in range(len(B)): if A[j]==B[k]: DP[j+1][k+1]=DP[j][k] else: DP[j+1][k+1]=min(DP[j+1][k], DP[j][k+1], DP[j][k])+1 cnt[i]=DP[len(A)][len(B)] for i in range(n): print(cnt[i])
s143901091
p02318
u481175672
1531849405
Python
Python3
py
Runtime Error
0
0
505
import numpy as np x=input() y=input() if(x==y): #同じなら0を出力して終了 print(0) exit() list = np.zeros((len(y)+1,len(x)+1)) for i in range(1,len(x)+1): list[0][i] = list[0][i-1]+1 for i in range(1,len(y)+1): list[i][0] = list[i-1][0]+1 for i in range(1,len(y)+1): for j in range(1,len(x)+1): a=list[i-1][j-1] b=list[i][j-1]+1 c=list[i-1][j]+1 if not(x[j-1] == y[i-1]): a=a+1 list[i][j]=min(a,b,c) print(int(list[len(y)][len(x)]))
s741964778
p02318
u481175672
1531849438
Python
Python3
py
Runtime Error
0
0
502
import numpy x=input() y=input() if(x==y): #同じなら0を出力して終了 print(0) exit() list = numpy.zeros((len(y)+1,len(x)+1)) for i in range(1,len(x)+1): list[0][i] = list[0][i-1]+1 for i in range(1,len(y)+1): list[i][0] = list[i-1][0]+1 for i in range(1,len(y)+1): for j in range(1,len(x)+1): a=list[i-1][j-1] b=list[i][j-1]+1 c=list[i-1][j]+1 if not(x[j-1] == y[i-1]): a=a+1 list[i][j]=min(a,b,c) print(int(list[len(y)][len(x)]))
s105192508
p02318
u408444038
1531862302
Python
Python3
py
Runtime Error
0
0
519
def L_common(str1,str2): d = [0 for i in range(len(str2)+1)] for n1 in str1: tmp = d[:] for (j,n2) in enumerate(str2): if n1 == n2: d[j+1] = tmp[j]+1 elif d[j+1]<d[j]: d[j+1] = d[j] return d[len(str2)] n = int(input()) stock = [] for i in range(n): x = input() y = input() if len(x)>len(y): stock.append(len(x)-L_common(x,y)) else: stock.append(len(y)-L_common(x,y)) for i in stock: print(i)
s859601026
p02318
u909075105
1531885351
Python
Python3
py
Runtime Error
0
0
300
def search(X,Y): n=len(X) m=len(Y) p=[i for i in range(m+1)] for i in range(n): q=list(range(m+1)) q[0] = i+1 for j in range(m): if X[i]==Y[j]: cost=0 else: cost=1 q[j+1]=min(p[j+1]+1,q[j]+1,p[j]+cost) p,q=q,p return pre[m] X=input() Y=input() print(search(X,Y))
s029241933
p02318
u209989098
1532167467
Python
Python3
py
Runtime Error
0
0
439
a = list(input()) b = list(input()) if len(a) == 0 or len(b) == 0: print(max(len(a),len(b))) else: dp = [[None for i in range(len(b)+1)] for j in range(len(a)+1)] for i in range(len(a)+1): dp[i][0] = i for i in range(len(b)+1): dp[0][i] = i for i in range(len(a)+1): for j in range(len(b)+1): aaa = dp[i-1][j-1] if a[i-1] == b[j-1] else dp[i-1][j-1]+1 dp[i][j] = min(aaa,dp[i-1][j] + 1,dp[i][j-1]+1) print(dp[-1][-1])
s085193172
p02318
u209989098
1532167589
Python
Python3
py
Runtime Error
0
0
441
a = list(input()) b = list(input()) if len(a) == 0 or len(b) == 0: print(max(len(a),len(b))) else: dp = [[None for i in range(len(b)+1)] for j in range(len(a)+1)] for i in range(len(a)+1): dp[i][0] = i for i in range(len(b)+1): dp[0][i] = i for i in range(1,len(a)+1): for j in range(len(b)+1): aaa = dp[i-1][j-1] if a[i-1] == b[j-1] else dp[i-1][j-1]+1 dp[i][j] = min(aaa,dp[i-1][j] + 1,dp[i][j-1]+1) print(dp[-1][-1])
s752941014
p02318
u886122084
1559462269
Python
Python3
py
Runtime Error
0
0
668
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline def leven(s1, s2): n1 = len(s1) n2 = len(s2) dp = [[0]*(n1+1) for _ in range(n2+1)] for i in range(1, n1+1): dp[0][i] = i for i in range(1, n2+1): dp[i][0] = i for j in range(1, n2+1): for k in range(1, n1+1): m = min(dp[j-1][k]+1, dp[j][k-1]) if s1[j-1] == s2[k-1]: # 最後の文字削除 m = min(m, dp[j-1][k-1]) else: m = min(m, dp[j-1][k-1]+1) dp[j][k] = m print(dp[-1][-1]) s1 = input()[:-1] s2 = input()[:-1] leven(s1, s2)
s572359005
p02318
u126202702
1447998449
Python
Python
py
Runtime Error
0
0
401
s1 = raw_input() s2 = raw_input() a = [[0 for i in range(len(s1) + 1)]for i in range(len(s2) + 1)] for i in range(len(s1) + 1): a[0][i] = i for i in range(len(s2) + 1): a[i][0] = i for i in range(len(s2)): for j in range(len(s1)): if s1[i] == s2[j]: a[j+1][i+1] = a[j][i] else: a[j+1][i+1] = min([a[j][i+1], a[j+1][i]) + 1 print a[len(s2)][len(s1)]