結果

問題 No.393 2本の竹
ユーザー tubo28tubo28
提出日時 2016-07-12 01:21:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,998 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 115,644 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-25 07:56:50
合計ジャッジ時間 4,677 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 462 ms
5,376 KB
testcase_10 AC 55 ms
5,376 KB
testcase_11 AC 88 ms
5,376 KB
testcase_12 AC 65 ms
5,376 KB
testcase_13 AC 92 ms
5,376 KB
testcase_14 AC 50 ms
5,376 KB
testcase_15 TLE -
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 #

#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() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    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());
        for (int i = n; i >= 0; --i) {

            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(i)) {
                cout << i << endl;
                break;
            }
        }
    }
}
0