結果

問題 No.393 2本の竹
ユーザー nebukuro09nebukuro09
提出日時 2017-01-03 18:02:45
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 198 ms / 1,000 ms
コード長 1,050 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 110,780 KB
実行使用メモリ 59,656 KB
最終ジャッジ日時 2023-09-03 00:22:58
合計ジャッジ時間 3,325 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 198 ms
59,656 KB
testcase_10 AC 50 ms
16,652 KB
testcase_11 AC 70 ms
17,888 KB
testcase_12 AC 79 ms
27,056 KB
testcase_13 AC 47 ms
14,444 KB
testcase_14 AC 16 ms
6,672 KB
testcase_15 AC 17 ms
13,936 KB
testcase_16 AC 38 ms
16,516 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 97 ms
40,272 KB
testcase_23 AC 44 ms
16,920 KB
testcase_24 AC 4 ms
5,360 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 166 ms
49,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void solve() {
    auto n = readln.split.map!(to!int).array.sort();
    auto m = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array.sort();
    auto acm = new int[](m);
    acm[0] = A[0];
    foreach (i; 1..m) acm[i] = acm[i-1] + A[i];

    auto dp = new int[][](m, n[0]+1);
    if (A[0] <= n[0]) dp[0][n[0]-A[0]] = 1;
    if (A[0] <= n[1]) dp[0][n[0]] = 1;

    foreach (i; 1..m) {
        foreach (j; 0..n[0]+1) { // j = 1本目の竹の残り
            int k = n[1] - (acm[i-1] - (n[0] - j)); // k = 2本目の竹の残り
            if (A[i] <= j) dp[i][j-A[i]] = max(dp[i][j-A[i]], dp[i-1][j] + 1);
            if (A[i] <= k) dp[i][j] = max(dp[i][j], dp[i-1][j] + 1);
        }
    }

    dp.map!(x => x.reduce!(max)).reduce!(max).writeln;
}

void main() {
    auto d = readln.chomp.to!int;
    foreach (i; 0..d)
        solve;
}
0