結果

問題 No.247 線形計画問題もどき
ユーザー しらっ亭しらっ亭
提出日時 2015-11-13 00:03:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 433 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 11,908 KB
最終ジャッジ日時 2023-10-11 15:46:09
合計ジャッジ時間 7,767 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
8,388 KB
testcase_01 AC 16 ms
7,820 KB
testcase_02 TLE -
testcase_03 AC 16 ms
7,740 KB
testcase_04 AC 16 ms
7,776 KB
testcase_05 AC 16 ms
7,876 KB
testcase_06 AC 16 ms
7,872 KB
testcase_07 AC 21 ms
8,832 KB
testcase_08 AC 71 ms
11,908 KB
testcase_09 AC 16 ms
7,792 KB
testcase_10 AC 20 ms
8,764 KB
testcase_11 AC 16 ms
7,900 KB
testcase_12 AC 16 ms
7,780 KB
testcase_13 AC 16 ms
7,784 KB
testcase_14 AC 16 ms
7,776 KB
testcase_15 AC 16 ms
7,828 KB
testcase_16 AC 16 ms
7,892 KB
testcase_17 AC 145 ms
8,168 KB
testcase_18 AC 46 ms
8,420 KB
testcase_19 AC 211 ms
8,516 KB
testcase_20 AC 1,016 ms
8,556 KB
testcase_21 AC 16 ms
7,776 KB
testcase_22 AC 32 ms
8,264 KB
testcase_23 AC 16 ms
8,192 KB
testcase_24 AC 935 ms
8,652 KB
testcase_25 AC 642 ms
8,480 KB
testcase_26 AC 21 ms
8,568 KB
testcase_27 AC 21 ms
8,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    C = int(input())
    N = int(input())
    A = list(map(int, input().split()))
    inf = float('inf')
    dp = [inf] * (C + 1)
    dp[0] = 0

    for i in range(C):
        if dp[i] != inf:
            for j in range(N):
                iaj = i + A[j]
                if iaj <= C:
                    dp[iaj] = min(dp[iaj], dp[i] + 1)
    print(dp[C] if dp[C] != inf else -1)


if __name__ == '__main__':
    solve()
0