結果

問題 No.393 2本の竹
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-07-05 16:41:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 1,000 ms
コード長 885 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 48,876 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 23:57:30
合計ジャッジ時間 1,575 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 28 ms
4,376 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 11 ms
4,376 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 18 ms
4,380 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 23 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
const int LIMITM=100000;
bool dp[2][LIMITM+2];
void f(){
	int n1,n2,n12,m;
	scanf("%d %d",&n1,&n2);
	scanf("%d",&m);
	n12=n1+n2;
	
	std::vector<int> vec;
	for(int i=0;i<m;i++){
		int e;
		scanf("%d",&e);
		vec.push_back(e);
	}
	std::sort(vec.begin(),vec.end());
	memset(dp,0,sizeof(dp));
	dp[0][n2]=true;
	int ans=0;
	for(int i=0;i<vec.size();i++){
		int a=vec[i];
		int now=i%2;
		int next=(i+1)%2;
		memset(dp[next],0,sizeof(dp[next]));
		bool hit=false;
		for(int j=0;(j<=n12)&&(j<=n2);j++){
			if(dp[now][j]==true){
				if((n12-j)>=a){
					dp[next][j]=true;
					hit=true;
				}
				if(j>=a){
					dp[next][j-a]=true;
					hit=true;
				}
			}
		}
		n12-=a;
		if(n12<0)break;
		if(hit==false)break;
		ans++;
	}
	printf("%d\n",ans);
}

int main(){
	int d;
	scanf("%d",&d);
	for(int i=0;i<d;i++){
		f();
	}
}
0