結果
問題 |
No.37 遊園地のアトラクション
|
ユーザー |
![]() |
提出日時 | 2015-06-10 01:29:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 999 bytes |
コンパイル時間 | 1,767 ms |
コンパイル使用メモリ | 63,256 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-10 12:58:20 |
合計ジャッジ時間 | 1,453 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <sstream> #include <vector> using namespace std; int main(int argc, char *argv[]) { string s; getline(cin, s); int T = atoi(s.c_str()); getline(cin, s); int N = atoi(s.c_str()); int C[16], V[16]; getline(cin, s); stringstream sa(s); for (int i = 0; i < N; ++i) { sa >> C[i]; } getline(cin, s); stringstream sb(s); for (int i = 0; i < N; ++i) { sb >> V[i]; } int dp[2][10002]; memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (int i = 0; i < N; ++i) { int prev = i & 1; int curr = prev ^ 1; memcpy(dp + curr, dp + prev, sizeof(dp[0])); for (int t = 0; t <= T; ++t) { int x = dp[prev][t]; if (x >= 0) { int v = V[i]; for (int j = t + C[i]; v > 0 && j <= T; j += C[i]) { x += v; v /= 2; dp[curr][j] = max(dp[curr][j], x); } } } } int ans = 0; for (int t = 0; t <= T; ++t) { ans = max(ans, dp[N & 1][t]); } cout << ans << endl; return 0; }