結果

問題 No.247 線形計画問題もどき
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-22 00:02:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 569 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 11,840 KB
実行使用メモリ 10,124 KB
最終ジャッジ日時 2023-10-21 12:06:18
合計ジャッジ時間 2,382 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 37 ms
10,060 KB
testcase_02 AC 32 ms
10,060 KB
testcase_03 AC 31 ms
10,060 KB
testcase_04 AC 33 ms
10,120 KB
testcase_05 AC 32 ms
10,060 KB
testcase_06 AC 32 ms
10,060 KB
testcase_07 AC 33 ms
10,060 KB
testcase_08 AC 33 ms
10,060 KB
testcase_09 AC 33 ms
10,060 KB
testcase_10 AC 31 ms
10,060 KB
testcase_11 AC 33 ms
10,120 KB
testcase_12 AC 31 ms
10,120 KB
testcase_13 AC 30 ms
10,060 KB
testcase_14 AC 31 ms
10,120 KB
testcase_15 AC 31 ms
10,060 KB
testcase_16 AC 30 ms
10,060 KB
testcase_17 WA -
testcase_18 AC 31 ms
10,120 KB
testcase_19 AC 36 ms
10,064 KB
testcase_20 WA -
testcase_21 AC 31 ms
10,064 KB
testcase_22 WA -
testcase_23 AC 30 ms
10,064 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 32 ms
10,060 KB
testcase_27 AC 31 ms
10,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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


def rec(i, val):
    if i == N - 1:
        if val % A[i] == 0:
            cnt.append(val // A[i])
            return True
        return False

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


rec(0, C)
if cnt:
    print(sum(cnt))
else:
    print(-1)
0