結果

問題 No.393 2本の竹
ユーザー ckawatakckawatak
提出日時 2019-01-08 23:25:29
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 864 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 9,016 KB
最終ジャッジ日時 2023-08-15 16:50:27
合計ジャッジ時間 18,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 721 ms
8,752 KB
testcase_01 AC 402 ms
8,824 KB
testcase_02 AC 664 ms
8,824 KB
testcase_03 AC 579 ms
8,948 KB
testcase_04 AC 360 ms
8,808 KB
testcase_05 AC 420 ms
8,824 KB
testcase_06 AC 296 ms
8,948 KB
testcase_07 AC 586 ms
8,820 KB
testcase_08 TLE -
testcase_09 RE -
testcase_10 AC 416 ms
8,912 KB
testcase_11 AC 733 ms
8,892 KB
testcase_12 AC 863 ms
9,016 KB
testcase_13 AC 651 ms
8,892 KB
testcase_14 AC 534 ms
8,956 KB
testcase_15 AC 92 ms
8,888 KB
testcase_16 AC 161 ms
8,812 KB
testcase_17 AC 644 ms
8,964 KB
testcase_18 AC 351 ms
8,824 KB
testcase_19 AC 201 ms
8,828 KB
testcase_20 AC 309 ms
8,820 KB
testcase_21 AC 665 ms
8,804 KB
testcase_22 AC 860 ms
8,824 KB
testcase_23 AC 433 ms
9,008 KB
testcase_24 AC 478 ms
8,824 KB
testcase_25 AC 568 ms
8,764 KB
testcase_26 AC 281 ms
8,992 KB
testcase_27 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

MAX = 100000

def accept(n1, n2, fragments, upper):
    if upper == 0:
        return True

    total = 0
    for i in range(upper):
        total = total + fragments[i]
    if n1+n2 < total:
        return False

    dp = [False for _ in range(MAX)]
    dp[0] = True

    for i in range(upper):
        for j in reversed(range(MAX)):
            if dp[j]:
                if j + fragments[i] <= n1:
                    dp[j + fragments[i]] = True

    for i in reversed(range(MAX)):
        if dp[i] and total - i <= n2:
            return True

    return False

N = int(input())
        
for i in range(N):
    n1, n2 = sorted(list(map(int, input().split(' '))))
    m = int(input())
    fragments = sorted(list(map(int, input().split(' '))))

    for j in reversed(range(0,m+1)):
        if accept(n1, n2, fragments, j):
            print(j)
            break
0