結果

問題 No.393 2本の竹
ユーザー kimiyukikimiyuki
提出日時 2016-10-21 15:34:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 77,584 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 10:25:42
合計ジャッジ時間 2,325 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 58 ms
4,376 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 21 ms
4,380 KB
testcase_12 AC 23 ms
4,376 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 12 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 12 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 28 ms
4,380 KB
testcase_23 AC 14 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 49 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    int dataset; cin >> dataset;
    while (dataset --) {
        // input
        int n1, n2, m; cin >> n1 >> n2 >> m;
        vector<int> as(m); repeat (i,m) cin >> as[i];
        // roughly estimate
        whole(sort, as);
        int acc = 0;
        int cnt = 0;
        for (int a : as) {
            if (n1 + n2 < acc + a) break;
            acc += a;
            ++ cnt;
        }
        // check the boundary
        vector<bool> dp(n1+1);
        dp[0] = true;
        for (int a : as) {
            repeat_reverse (i, n1) if (dp[i]) {
                if (i + a < n1+1) {
                    dp[i + a] = true;
                }
            }
        }
        int last = n1;
        while (not dp[last]) -- last;
        bool found = (acc - last <= n2);
        // output
        cout << (cnt - not found) << endl;
    }
    return 0;
}
0