結果

問題 No.393 2本の竹
ユーザー tubo28tubo28
提出日時 2016-07-12 01:16:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 1,000 ms
コード長 2,057 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 116,792 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 18:08:58
合計ジャッジ時間 2,479 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 115 ms
6,940 KB
testcase_10 AC 26 ms
6,944 KB
testcase_11 AC 37 ms
6,940 KB
testcase_12 AC 41 ms
6,944 KB
testcase_13 AC 25 ms
6,940 KB
testcase_14 AC 14 ms
6,940 KB
testcase_15 AC 28 ms
6,944 KB
testcase_16 AC 38 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 49 ms
6,940 KB
testcase_23 AC 28 ms
6,944 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 83 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(i,k) for (int i = 0; i < (int)(k); i++)
#define all(c) begin(c), end(c)


int main() {
    int d;
    cin >> d;
    for (int i = 0; i < d; i++) {
        int a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        int n;
        cin >> n;
        vector<int> x(n);
        for (int i = 0; i < n; i++) {
            cin >> x[i];
        }
        sort(x.begin(), x.end());
        int lb = 0, ub = n + 1;
        while (lb + 1 < ub) {
            int mid = (ub + lb) / 2;

            auto can = [&](int k) {
                int s = accumulate(x.begin(), x.begin() + k, 0);
                vector<int> dp(s + 1);
                dp[0] = true;
                for (int i = 0; i < k; ++i) {
                    for (int j = s; j >= x[i]; --j) {
                        dp[j] |= dp[j - x[i]];
                    }
                }
                for (int i = 0; i <= s; i++) {
                    if (dp[i]) {
                        int sa = i;
                        int sb = s - i;
                        if (sa > sb) swap(sa, sb);
                        if (sa <= a && sb <= b) return true;
                    }
                }
                return false;
            };

            if (can(mid)) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        cout << lb << endl;
    }
}
0