結果

問題 No.247 線形計画問題もどき
ユーザー しらっ亭しらっ亭
提出日時 2015-11-13 00:05:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 468 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 12,116 KB
最終ジャッジ日時 2023-10-11 15:46:23
合計ジャッジ時間 6,624 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
8,600 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 TLE -
testcase_03 AC 15 ms
7,776 KB
testcase_04 AC 16 ms
7,836 KB
testcase_05 AC 16 ms
7,788 KB
testcase_06 AC 16 ms
7,780 KB
testcase_07 AC 20 ms
8,776 KB
testcase_08 AC 71 ms
11,824 KB
testcase_09 AC 15 ms
7,776 KB
testcase_10 AC 21 ms
8,812 KB
testcase_11 AC 15 ms
7,824 KB
testcase_12 AC 15 ms
7,792 KB
testcase_13 AC 16 ms
7,776 KB
testcase_14 AC 15 ms
7,776 KB
testcase_15 AC 15 ms
7,772 KB
testcase_16 AC 16 ms
7,844 KB
testcase_17 AC 76 ms
8,216 KB
testcase_18 AC 46 ms
8,380 KB
testcase_19 AC 94 ms
8,584 KB
testcase_20 AC 740 ms
8,468 KB
testcase_21 AC 16 ms
7,876 KB
testcase_22 AC 19 ms
8,308 KB
testcase_23 AC 17 ms
8,096 KB
testcase_24 AC 688 ms
8,720 KB
testcase_25 AC 447 ms
8,528 KB
testcase_26 AC 19 ms
8,548 KB
testcase_27 AC 19 ms
8,216 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

    A.sort()

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


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