結果
問題 |
No.54 Happy Hallowe'en
|
ユーザー |
![]() |
提出日時 | 2014-12-13 19:28:54 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 871 bytes |
コンパイル時間 | 629 ms |
コンパイル使用メモリ | 44,672 KB |
実行使用メモリ | 392,764 KB |
最終ジャッジ日時 | 2024-06-11 21:05:16 |
合計ジャッジ時間 | 18,784 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf( "%d", &N ); | ~~~~~^~~~~~~~~~~~ main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 38 | scanf( "%d%d", &V, &T ); | ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio> #include<cstring> #include<algorithm> #include<functional> #include<utility> #define rep(i,a) for(int i=0;i<(a);++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]; int dp[MAX_N][MAX_N+1]; int rec( int i, int c ) { if( i == N ) return c; int &ret = dp[i][c]; if( ~ret ) return ret; if( c >= ps[i].first ) return ret = rec( i+1, c ); else return ret = std::max( rec( i+1, c ), rec( i+1, std::min( MAX_N, c+ps[i].second ) ) ); } int main() { scanf( "%d", &N ); rep( i, N ) { int V, T; scanf( "%d%d", &V, &T ); ps[i] = P( T, V ); } std::sort( ps, ps+N, []( const P &lhs, const P &rhs ){ return lhs.first+lhs.second < rhs.first+rhs.second; } ); clr( dp, -1 ); printf( "%d\n", rec( 0, 0 ) ); return 0; }