結果

問題 No.393 2本の竹
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-07-13 08:51:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,174 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 176,480 KB
実行使用メモリ 51,616 KB
最終ジャッジ日時 2024-04-23 01:52:32
合計ジャッジ時間 4,556 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 6 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 13 ms
5,376 KB
testcase_08 AC 39 ms
5,376 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 #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

int m;
vector<int> a;
map<Pii, int> memo;
int dfs(int r1, int r2, int i) {
    if (r1 < 0 || r2 < 0) return i - 1;
    if (i >= m) return i;
    if (memo[Pii(r1, r2)] != 0) return memo[Pii(r1, r2)];
    return memo[Pii(r1, r2)] = max(dfs(r1 - a[i], r2, i + 1), dfs(r1, r2 - a[i], i + 1));
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int d;
    cin >> d;
    rep(_, d) {
        int n1, n2;
        cin >> n1 >> n2;
        cin >> m;
        a.resize(m);
        rep(i, m) cin >> a[i];
        sort(all(a));
        memo.clear();
        cout << dfs(n1, n2, 0) << endl;
    }

}
0