結果
| 問題 | No.247 線形計画問題もどき |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-13 11:29:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,250 bytes |
| コンパイル時間 | 369 ms |
| コンパイル使用メモリ | 82,116 KB |
| 実行使用メモリ | 849,132 KB |
| 最終ジャッジ日時 | 2025-02-13 11:29:12 |
| 合計ジャッジ時間 | 6,028 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 22 MLE * 1 |
ソースコード
import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
sys.set_int_max_str_digits(10 ** 6)
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]
def main():
C = NI()
N = NI()
A = NLI()
B = []
for a in A:
for t in range(20):
if a * (1<<t) <= C:
B.append([a*(1<<t), (1<<t)])
# print(B)
N = len(B)
INF = 10**18
# i個見たときでfの値がjのときの個数
dp = [[INF]*(C+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
b, t = B[i]
for j in range(C+1):
dp[i+1][j] = min(dp[i+1][j], dp[i][j])
if j+b <= C:
dp[i+1][j+b] = min(dp[i+1][j+b], dp[i][j] + t)
ans = dp[N][C]
print(ans if ans < INF else -1)
if __name__ == "__main__":
main()