結果

問題 No.393 2本の竹
ユーザー itezpaceitezpace
提出日時 2016-10-04 10:54:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,232 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 68,216 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 11:32:01
合計ジャッジ時間 1,734 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 24 ms
6,940 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 AC 12 ms
6,940 KB
testcase_12 AC 14 ms
6,944 KB
testcase_13 AC 8 ms
6,944 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 WA -
testcase_17 AC 2 ms
6,940 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 WA -
testcase_22 AC 17 ms
6,944 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 21 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int d;cin>>d;
  for(int i=0;i<d;++i){
    int n1,n2;cin>>n1>>n2;
    int m;cin>>m;
    vector<int> v(m);
    for(int j=0;j<m;++j){
      cin>>v[j];
    }
    sort(v.begin(),v.end());
    int n3=n1+n2;
    int n4=min(n1,n2);
    int n5=max(n1,n2);
    int sum=0;
    int cut=0;
    for(int j=0;j<m;++j){
      if(n3>=sum+v[j] && n4>=v[j]){
        sum+=v[j];
      } else {
        v.erase(v.begin()+j-cut);
        cut+=1;
      }
    }
    cerr<<endl;
    if(v.size()==0){
      cout<<0<<endl;
      continue;
    }
    int diff=n3-sum;
    int dp[n4+1];
    vector<int> v2=v;
    int ans=0;
    while(1){
      for(int k=0;k<n4+1;++k){
        dp[k]=0;
      }
      dp[v[0]]=v2[0];
      for(int k=1;k<v2.size();++k){
        for(int l=0;l<n4+1;++l){
          if(dp[l]){
            if(l+v2[k]>n4) continue;
            dp[l+v2[k]]=v2[k];
          }
        }
      }
      int check=0;
      for(int k=n4;k>=n4-diff;--k){
        if(dp[k]) check=1;
      }
      if(check==1){
        ans=v2.size();
        break;
      } else {
        diff+=v2[v2.size()-1];
        v2.erase(v2.end()-1);
      }
    }
    cout<<ans<<endl;
  }
}
0