結果

問題 No.54 Happy Hallowe'en
ユーザー cielciel
提出日時 2015-04-09 12:08:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 628 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 46,464 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 16:40:51
合計ジャッジ時間 1,247 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 12 ms
5,376 KB
testcase_07 AC 18 ms
5,376 KB
testcase_08 AC 23 ms
5,376 KB
testcase_09 AC 30 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 28 ms
5,376 KB
testcase_13 AC 30 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
main.cpp:9:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |                 scanf("%d%d",&v[i].first,&v[i].second);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
int main(){
	int n,vmax=0,tmax=0;
	scanf("%d",&n);
	std::vector<std::pair<int,int> >v(n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&v[i].first,&v[i].second);
		if(vmax<v[i].first)vmax=v[i].first;
		if(tmax<v[i].second)tmax=v[i].second;
	}
	std::sort(v.begin(),v.end(),[](std::pair<int,int> a,std::pair<int,int> b)->bool{return a.first+a.second<b.first+b.second;});
	std::vector<int>bag(tmax+vmax+1);
	bag[0]=1;
	for(int i=0;i<n;i++){
		for(int j=v[i].second-1;j>=0;j--)bag[j+v[i].first]|=bag[j];
	}
	for(int i=tmax+vmax;i>=0;i--)if(bag[i]){
		printf("%d\n",i);
		break;
	}
}
0