結果
| 問題 |
No.54 Happy Hallowe'en
|
| コンテスト | |
| ユーザー |
Ysmr_Ry
|
| 提出日時 | 2014-12-14 10:44:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 5,000 ms |
| コード長 | 850 bytes |
| コンパイル時間 | 386 ms |
| コンパイル使用メモリ | 39,040 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 17:10:56 |
| 合計ジャッジ時間 | 1,473 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | scanf( "%d", &N );
| ~~~~~^~~~~~~~~~~~
main.cpp:23:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf( "%d%d", &V, &T );
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<utility>
#define rep(i,a) for(int i=0;i<(a);++i)
#define repd(i,a) for(int i=(a);i>=0;--i)
#define clr(a,v) memset((a),(v),sizeof(a))
typedef std::pair<int, int> P;
const int MAX_N = 10000;
int N;
P ps[MAX_N];
bool dp[MAX_N+1];
int main()
{
scanf( "%d", &N );
rep( i, N )
{
int V, T;
scanf( "%d%d", &V, &T );
ps[i] = P( V, T );
}
std::sort( ps, ps+N, []( const P &lhs, const P &rhs ){ return lhs.first+lhs.second < rhs.first+rhs.second; } );
clr( dp, false );
dp[0] = true;
int ans = 0;
rep( i, N )
{
repd( j, ps[i].second-1 )
{
if( !dp[j] )
continue;
ans = std::max( ans, j+ps[i].first );
if( j+ps[i].first <= MAX_N )
dp[j+ps[i].first] |= dp[j];
}
}
printf( "%d\n", ans );
return 0;
}
Ysmr_Ry