結果

問題 No.393 2本の竹
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-07-14 17:45:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 855 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 26,000 KB
最終ジャッジ日時 2024-04-23 01:53:40
合計ジャッジ時間 3,274 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
18,080 KB
testcase_01 AC 35 ms
10,880 KB
testcase_02 AC 43 ms
10,880 KB
testcase_03 AC 55 ms
11,008 KB
testcase_04 AC 35 ms
10,752 KB
testcase_05 AC 42 ms
11,008 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 76 ms
11,008 KB
testcase_08 AC 118 ms
11,136 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# after reading the editorials

import array


UNDEF = -1


def solve(n1, n2, m, xs0):
    xs = sorted(xs0)
    dp = [array.array("i", (UNDEF for _ in range(n1 + 1)))
          for _ in range(m + 1)]
    dp[0][0] = 0
    s = 0
    for i in range(m):
        for j in range(n1 + 1):
            if dp[i][j] >= 0:
                c1 = j + xs[i]
                c2 = s - j + xs[i]
                if c1 <= n1:
                    dp[i + 1][c1] = dp[i][j] + 1
                if c2 <= n2:
                    dp[i + 1][j] = dp[i][j] + 1
        s += xs[i]
    return max(max(dpr) for dpr in dp)


def main():
    d = int(input())
    for _ in range(d):
        n1, n2 = map(int, input().split())
        m = int(input())
        xs = map(int, input().split())
        print(solve(n1, n2, m, xs))


if __name__ == '__main__':
    main()
0