結果

問題 No.247 線形計画問題もどき
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-09-10 17:14:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 416 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 81,388 KB
最終ジャッジ日時 2023-08-17 21:25:41
合計ジャッジ時間 5,367 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
79,572 KB
testcase_01 AC 112 ms
77,504 KB
testcase_02 AC 197 ms
79,820 KB
testcase_03 AC 106 ms
73,032 KB
testcase_04 AC 108 ms
72,760 KB
testcase_05 AC 109 ms
72,708 KB
testcase_06 AC 111 ms
72,876 KB
testcase_07 AC 124 ms
81,388 KB
testcase_08 AC 112 ms
77,976 KB
testcase_09 AC 109 ms
73,012 KB
testcase_10 AC 115 ms
79,500 KB
testcase_11 AC 107 ms
72,996 KB
testcase_12 AC 109 ms
73,004 KB
testcase_13 AC 108 ms
73,000 KB
testcase_14 AC 110 ms
72,920 KB
testcase_15 AC 108 ms
72,760 KB
testcase_16 AC 109 ms
72,816 KB
testcase_17 AC 134 ms
79,928 KB
testcase_18 AC 116 ms
77,292 KB
testcase_19 AC 161 ms
80,164 KB
testcase_20 AC 173 ms
80,828 KB
testcase_21 AC 123 ms
77,496 KB
testcase_22 AC 130 ms
78,788 KB
testcase_23 AC 125 ms
77,420 KB
testcase_24 AC 176 ms
81,252 KB
testcase_25 AC 160 ms
81,384 KB
testcase_26 AC 125 ms
79,640 KB
testcase_27 AC 136 ms
79,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import math,sys
input = sys.stdin.readline

C = int(input())
N = int(input())
A = list(map(int,input().split()))

INF = (1<<60)
dp = [INF]*(C+2)

dp[0] = 0
for a in A:
    
    for i in range(C):
        
        dp[min(C+1,i+a)] = min(dp[min(C+1,i+a)],dp[i]+1)
        
if dp[C]==INF:
    print(-1)
else:
    print(dp[C])
0