結果

問題 No.393 2本の竹
ユーザー ctyl_0ctyl_0
提出日時 2016-07-12 02:11:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 1,918 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 93,668 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 18:12:30
合計ジャッジ時間 2,440 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,816 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,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 121 ms
6,940 KB
testcase_10 AC 32 ms
6,944 KB
testcase_11 AC 44 ms
6,944 KB
testcase_12 AC 52 ms
6,940 KB
testcase_13 AC 33 ms
6,940 KB
testcase_14 AC 22 ms
6,940 KB
testcase_15 AC 10 ms
6,940 KB
testcase_16 AC 32 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 62 ms
6,944 KB
testcase_23 AC 30 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 100 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
struct cut {
    int cnt1, cnt2, sum2;
};

bool isZero(cut c){
    if(c.cnt1 == 0 && c.cnt2 == 0 && c.sum2 == 0) return true;
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int d;
    cin >> d;
    rep(i, d){
        int n1, n2, m;
        cin >> n1 >> n2 >> m;
        vector<int> A(m);
        rep(i, m) cin >> A[i];
        sort(all(A));
        vector<cut> check(n1 + 1, {0, 0, 0});
        vector<cut> tmp(n1 + 1, {0, 0, 0});
        int ret = 0;
        rep(i, m){
            if(i == 0){
                if(A[i] <= n1) tmp[A[i]] = {1, 0, 0};
                if(A[i] <= n2) tmp[0] = {0, 1, A[i]};
            }
            else {
                rep(j, n1 + 1){
                    if(!isZero(check[j])){
                        if(j + A[i] <= n1) tmp[j + A[i]] = {check[j].cnt1 + 1, check[j].cnt2, check[j].sum2};
                        if(check[j].sum2 + A[i] <= n2) tmp[j] = {check[j].cnt1, check[j].cnt2 + 1, check[j].sum2 + A[i]};
                    }
                }
            }
            check = tmp;
            rep(j, n1 + 1) {
                ret = max(ret, check[j].cnt1 + check[j].cnt2);
            }
        }
        
        output(ret, 0);
        
    }
    
    return 0;
}
0