結果

問題 No.247 線形計画問題もどき
ユーザー ynyn
提出日時 2016-08-31 22:44:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 492 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 158,592 KB
最終ジャッジ日時 2024-04-26 22:01:39
合計ジャッジ時間 5,833 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 50 ms
59,264 KB
testcase_02 AC 1,073 ms
158,592 KB
testcase_03 AC 40 ms
51,840 KB
testcase_04 AC 40 ms
51,968 KB
testcase_05 AC 40 ms
52,224 KB
testcase_06 AC 40 ms
52,096 KB
testcase_07 AC 64 ms
70,912 KB
testcase_08 AC 58 ms
68,480 KB
testcase_09 AC 40 ms
51,584 KB
testcase_10 AC 53 ms
66,816 KB
testcase_11 AC 40 ms
51,712 KB
testcase_12 AC 40 ms
51,968 KB
testcase_13 AC 40 ms
51,840 KB
testcase_14 AC 41 ms
51,712 KB
testcase_15 AC 41 ms
51,584 KB
testcase_16 AC 40 ms
51,712 KB
testcase_17 WA -
testcase_18 AC 58 ms
63,744 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 86 ms
69,120 KB
testcase_22 WA -
testcase_23 AC 99 ms
70,912 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 120 ms
89,472 KB
testcase_27 AC 133 ms
90,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

c = int(input())
n = int(input())
a = [0] + list(map(int,input().split()))

dp = [[10 ** 10] * (n + 1) for i in range(c + 1)]
for i in range(n + 1):
    dp[0][i] = 0

for i in range(1, n + 1):
    for j in range(c + 1):
        if j + a[i] <= c:
            dp[j + a[i]][i] = min(dp[j + a[i]][i], dp[j + a[i]][i-1], dp[j][i] + 1, dp[j][i - 1] + 1)

    if a[i] > c:
        for j in range(c + 1):
            dp[j][i] = dp[j][i-1]

if dp[c][n] >= 10 ** 10:
    dp[c][n] = -1

print(dp[c][n])
0