結果

問題 No.288 貯金箱の仕事
ユーザー convexineqconvexineq
提出日時 2020-12-31 02:24:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,233 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 416,896 KB
最終ジャッジ日時 2024-04-17 04:03:02
合計ジャッジ時間 6,438 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
80,128 KB
testcase_01 AC 57 ms
62,208 KB
testcase_02 AC 47 ms
54,016 KB
testcase_03 AC 47 ms
53,504 KB
testcase_04 AC 46 ms
53,632 KB
testcase_05 AC 80 ms
74,624 KB
testcase_06 AC 46 ms
53,632 KB
testcase_07 AC 123 ms
77,056 KB
testcase_08 AC 97 ms
76,672 KB
testcase_09 AC 119 ms
76,928 KB
testcase_10 AC 114 ms
77,056 KB
testcase_11 AC 97 ms
76,672 KB
testcase_12 AC 102 ms
76,928 KB
testcase_13 AC 106 ms
76,800 KB
testcase_14 AC 107 ms
76,928 KB
testcase_15 AC 110 ms
76,800 KB
testcase_16 AC 102 ms
76,928 KB
testcase_17 AC 93 ms
76,672 KB
testcase_18 AC 77 ms
70,656 KB
testcase_19 AC 89 ms
76,416 KB
testcase_20 AC 78 ms
71,168 KB
testcase_21 AC 76 ms
69,888 KB
testcase_22 AC 108 ms
77,056 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def knapsack_limited(vlst,wlst,mlst,W):
    from collections import deque
    INF = 1<<60
    V = sum(vi*mi for vi,mi in zip(vlst,mlst))
    dp = [INF]*(V+1)
    dp[0] = 0
    Vnow = 0
    for vi,wi,mi in zip(vlst,wlst,mlst):
        Vnow += vi*mi
        for i in range(vi):
            q1 = deque() #idx
            q2 = deque() #val
            for j in range(V+1):
                x = vi*j + i
                if x > Vnow: break
                vx = dp[x] - j*wi
                while q2 and q2[-1] > vx:
                    q1.pop(); q2.pop()
                q1.append(j)
                q2.append(vx)
                dp[x] = q2[0] + j*wi
                if j - q1[0] == mi:
                    q1.popleft(); q2.popleft()
    return dp

n,m = map(int,input().split())
*a, = map(int,input().split())
*k, = map(int,input().split())

num = [0]*(n-1)
for i in range(n-1):
    num[i] = a[i+1]-1
dp = knapsack_limited(a[:n-1],[1]*(n-1),num,0)
#print(dp)
an,kn = a[-1],k[-1]
tot = sum(ai*ki for ai,ki in zip(a,k)) - an*kn
ans = INF = 1<<60
for i,x in enumerate(dp):
    if x==INF: continue
    c = tot-i-m
    if c%an==0 and -c <= an*kn:
        #print(c,i,x,c//an)
        ans = min(ans,x + kn + c//an)
print(ans if ans < INF else -1)
0