結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
tossy
|
| 提出日時 | 2016-07-21 00:48:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 1,000 ms |
| コード長 | 1,835 bytes |
| コンパイル時間 | 879 ms |
| コンパイル使用メモリ | 94,468 KB |
| 実行使用メモリ | 29,056 KB |
| 最終ジャッジ日時 | 2024-11-08 09:26:59 |
| 合計ジャッジ時間 | 3,225 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#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;
}
tossy