結果

問題 No.54 Happy Hallowe'en
ユーザー ey429ey429
提出日時 2015-03-01 00:13:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 221 ms / 5,000 ms
コード長 619 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 61,544 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 20:06:17
合計ジャッジ時間 2,321 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 56 ms
4,380 KB
testcase_05 AC 80 ms
4,380 KB
testcase_06 AC 103 ms
4,380 KB
testcase_07 AC 140 ms
4,380 KB
testcase_08 AC 165 ms
4,380 KB
testcase_09 AC 190 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 221 ms
4,380 KB
testcase_13 AC 186 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<algorithm>
#include<map>
#define M 20000
using namespace std;
typedef pair<int,int> P;
P ord[10000];
int V[10000];
int T[10000];
bool dp[2][M+1];

int main(){
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&V[i],&T[i]);
		ord[i]=P(V[i]+T[i],i);
	}
	sort(ord,ord+n);
	for(i=0;i<=M;i++){
		dp[0][i]=false;
		dp[1][i]=false;
	}
	dp[0][0]=true;
	for(i=0;i<n;i++){
		int p=i%2;
		int q=(i+1)%2;
		int t=ord[i].second;
		for(j=M-V[t];j>=0;j--){
			dp[q][j]|=dp[p][j];
			dp[q][j+V[t]]|=dp[p][j]&&j<T[t];
		}
	}
	for(i=M;i>=0;i--)if(dp[n%2][i])break;
	printf("%d\n",i);
	return 0;
}
0