結果

問題 No.247 線形計画問題もどき
ユーザー tktk_snsn
提出日時 2020-12-22 00:06:58
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 514 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 17,824 KB
最終ジャッジ日時 2024-09-21 13:25:04
合計ジャッジ時間 3,732 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 5
other AC * 2 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18

C = int(input())
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = []
ans = inf


def rec(i, val):
    global ans
    if i == N:
        if val == 0:
            ans = min(ans, sum(cnt))
        return

    x_max = val // A[i]
    for x in reversed(range(x_max + 1)):
        cnt.append(x)
        rec(i + 1, val - A[i] * x)
        cnt.pop()


rec(0, C)
if ans >= inf:
    ans = -1

print(ans)
0