結果

問題 No.393 2本の竹
ユーザー tossytossy
提出日時 2016-07-21 00:48:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 1,000 ms
コード長 1,835 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 96,024 KB
実行使用メモリ 29,296 KB
最終ジャッジ日時 2024-04-25 21:28:32
合計ジャッジ時間 2,956 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
29,076 KB
testcase_01 AC 40 ms
29,136 KB
testcase_02 AC 41 ms
29,084 KB
testcase_03 AC 40 ms
29,172 KB
testcase_04 AC 39 ms
29,088 KB
testcase_05 AC 35 ms
29,156 KB
testcase_06 AC 37 ms
29,084 KB
testcase_07 AC 34 ms
29,296 KB
testcase_08 AC 38 ms
29,172 KB
testcase_09 AC 74 ms
29,156 KB
testcase_10 AC 48 ms
29,084 KB
testcase_11 AC 55 ms
29,244 KB
testcase_12 AC 57 ms
29,100 KB
testcase_13 AC 47 ms
28,944 KB
testcase_14 AC 40 ms
29,156 KB
testcase_15 AC 13 ms
28,988 KB
testcase_16 AC 30 ms
29,128 KB
testcase_17 AC 31 ms
28,996 KB
testcase_18 AC 40 ms
29,056 KB
testcase_19 AC 30 ms
29,084 KB
testcase_20 AC 39 ms
29,100 KB
testcase_21 AC 38 ms
29,140 KB
testcase_22 AC 63 ms
28,956 KB
testcase_23 AC 48 ms
29,272 KB
testcase_24 AC 36 ms
29,096 KB
testcase_25 AC 34 ms
29,064 KB
testcase_26 AC 30 ms
29,120 KB
testcase_27 AC 63 ms
29,084 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( l>=vec[i] && 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