結果
| 問題 |
No.37 遊園地のアトラクション
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-20 21:00:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,211 bytes |
| コンパイル時間 | 404 ms |
| コンパイル使用メモリ | 51,916 KB |
| 最終ジャッジ日時 | 2024-11-14 19:20:32 |
| 合計ジャッジ時間 | 958 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:9:1: error: ‘vector’ does not name a type
9 | vector<int> c, v;
| ^~~~~~
main.cpp:10:1: error: ‘vector’ does not name a type
10 | vector<vector<vector<int>>> dp;
| ^~~~~~
main.cpp: In function ‘int calc(int, int)’:
main.cpp:13:13: error: ‘v’ was not declared in this scope
13 | int res = v[i];
| ^
main.cpp: In function ‘int rec(int, int, int)’:
main.cpp:21:14: error: ‘dp’ was not declared in this scope
21 | int &res = dp[i][j][t];
| ^~
main.cpp:25:8: error: ‘c’ was not declared in this scope
25 | if(t+c[i] <= tt && j < 13) {
| ^
main.cpp: In function ‘int main()’:
main.cpp:33:3: error: ‘c’ was not declared in this scope
33 | c.resize(n);
| ^
main.cpp:34:3: error: ‘v’ was not declared in this scope
34 | v.resize(n);
| ^
main.cpp:37:3: error: ‘dp’ was not declared in this scope
37 | dp.assign(n+1, vector<vector<int>>(15, vector<int>(tt+1, -1)));
| ^~
main.cpp:37:18: error: ‘vector’ was not declared in this scope
37 | dp.assign(n+1, vector<vector<int>>(15, vector<int>(tt+1, -1)));
| ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
main.cpp:37:32: error: expected primary-expression before ‘int’
37 | dp.assign(n+1, vector<vector<int>>(15, vector<int>(tt+1, -1)));
| ^~~
main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | scanf("%d%d", &tt, &n);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
int tt, n;
vector<int> c, v;
vector<vector<vector<int>>> dp;
int calc(int i, int j) {
int res = v[i];
for(int loop : range(j)) { res /= 2; }
return res;
}
// 今t時間経った。i番目のアトラクションのj回目(j>=0)に乗ろうか悩んでいる。
// そのときの満足度の最大値を求める。
int rec(int t, int i, int j) {
int &res = dp[i][j][t];
if(res != -1) { return res; }
if(i == n) { return res = 0; }
res = rec(t, i+1, 0); // 乗らない
if(t+c[i] <= tt && j < 13) {
res = max(res, rec(t+c[i], i, j+1) + calc(i, j)); // 乗る
}
return res;
}
int main(void) {
scanf("%d%d", &tt, &n);
c.resize(n);
v.resize(n);
for(int i : range(n)) { scanf("%d", &c[i]); }
for(int i : range(n)) { scanf("%d", &v[i]); }
dp.assign(n+1, vector<vector<int>>(15, vector<int>(tt+1, -1)));
int res = rec(0, 0, 0);
printf("%d\n", res);
return 0;
}