結果

問題 No.393 2本の竹
ユーザー ckawatakckawatak
提出日時 2019-01-08 23:41:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 853 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 8,952 KB
最終ジャッジ日時 2023-08-15 16:50:52
合計ジャッジ時間 6,324 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
7,964 KB
testcase_01 AC 17 ms
7,896 KB
testcase_02 AC 17 ms
7,788 KB
testcase_03 AC 19 ms
7,832 KB
testcase_04 AC 16 ms
7,784 KB
testcase_05 AC 18 ms
7,852 KB
testcase_06 AC 16 ms
7,824 KB
testcase_07 AC 21 ms
7,820 KB
testcase_08 AC 27 ms
7,836 KB
testcase_09 TLE -
testcase_10 AC 205 ms
8,816 KB
testcase_11 AC 348 ms
8,892 KB
testcase_12 AC 464 ms
8,732 KB
testcase_13 AC 220 ms
8,424 KB
testcase_14 AC 73 ms
8,196 KB
testcase_15 AC 38 ms
8,496 KB
testcase_16 AC 77 ms
8,952 KB
testcase_17 AC 22 ms
7,888 KB
testcase_18 AC 18 ms
7,824 KB
testcase_19 AC 17 ms
7,904 KB
testcase_20 AC 16 ms
7,756 KB
testcase_21 AC 21 ms
7,812 KB
testcase_22 AC 585 ms
8,756 KB
testcase_23 AC 178 ms
8,892 KB
testcase_24 AC 28 ms
8,200 KB
testcase_25 AC 22 ms
7,816 KB
testcase_26 AC 16 ms
7,832 KB
testcase_27 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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(n1+1)]
    dp[0] = True

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

    for i in reversed(range(n1+1)):
        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