結果

問題 No.393 2本の竹
ユーザー tossytossy
提出日時 2016-07-21 00:45:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,822 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 95,040 KB
実行使用メモリ 29,312 KB
最終ジャッジ日時 2024-04-23 19:20:02
合計ジャッジ時間 3,468 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
29,056 KB
testcase_01 WA -
testcase_02 AC 34 ms
29,056 KB
testcase_03 AC 33 ms
29,056 KB
testcase_04 AC 33 ms
28,928 KB
testcase_05 AC 30 ms
29,184 KB
testcase_06 AC 34 ms
29,056 KB
testcase_07 AC 35 ms
29,056 KB
testcase_08 AC 34 ms
29,056 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 48 ms
29,056 KB
testcase_12 AC 49 ms
28,928 KB
testcase_13 AC 41 ms
29,056 KB
testcase_14 AC 36 ms
28,928 KB
testcase_15 AC 23 ms
29,056 KB
testcase_16 RE -
testcase_17 AC 34 ms
29,056 KB
testcase_18 AC 36 ms
28,928 KB
testcase_19 AC 29 ms
29,056 KB
testcase_20 AC 33 ms
29,056 KB
testcase_21 AC 34 ms
29,056 KB
testcase_22 AC 59 ms
29,056 KB
testcase_23 RE -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 31 ms
29,056 KB
testcase_27 AC 63 ms
28,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

int dp[65][100005];
int sums[65];
// index, smaller bamboo length

int main(){
    int d;
    cin>>d;
    while(d-->0){
        int n1,n2,q;
        cin>>n1>>n2>>q;

        vector<int> vec(q);
        rep(i,q) scanf("%d", &vec[i]);
        sort(all(vec));
        sums[0]=vec[0];
        repl(i,1,q) sums[i] = vec[i]+sums[i-1];

        if(n1>n2) swap(n1,n2);
        // n1 <= n2

        fill(dp[0],dp[65],0);

        if(vec[0]>n2){
            cout<<0<<endl;
            continue;
        }

        int res=1;
        if(vec[0]<=n1) dp[0][vec[0]] = 1;
        dp[0][0] = 1;
        for(int i=1; i<q; i++){
            bool update=false;
            for(int l=max(0,sums[i]-n2); l<=n1; l++){   // required sums[i]-l<=n2
                if( dp[i-1][l-vec[i]] ){
                    // use vec[i] to shorter one
                    dp[i][l]=1;
                    update=true;

                }

                if( dp[i-1][l] ){
                    // use vec[i] to longer one
                    dp[i][l]=1;
                    update=true;
                }
            }
            if(!update){
                res = i;
                break;
            }
            if(i==q-1) res=q;
        }
        cout<<res<<endl;
  }

  return 0;
}
0