結果
| 問題 |
No.266 最終進化を目指せ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-18 23:36:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,116 bytes |
| コンパイル時間 | 337 ms |
| コンパイル使用メモリ | 52,396 KB |
| 最終ジャッジ日時 | 2024-11-14 19:09:24 |
| 合計ジャッジ時間 | 655 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:3: error: ‘vector’ was not declared in this scope
10 | vector<int> s(n+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:10:10: error: expected primary-expression before ‘int’
10 | vector<int> s(n+1);
| ^~~
main.cpp:11:42: error: ‘s’ was not declared in this scope
11 | for(int i=0; i<=n; i++) { scanf("%d", &s[i]); }
| ^
main.cpp:12:17: error: expected primary-expression before ‘int’
12 | vector<vector<int>> dp(n+1, vector<int>(s[n]+1));
| ^~~
main.cpp:14:21: error: ‘s’ was not declared in this scope
14 | for(int j=0; j<=s[i]; j++) { dp[i][j] = inf; }
| ^
main.cpp:14:34: error: ‘dp’ was not declared in this scope
14 | for(int j=0; j<=s[i]; j++) { dp[i][j] = inf; }
| ^~
main.cpp:15:15: error: ‘s’ was not declared in this scope
15 | for(int j=s[i]+1; j<=s[n]; j++) { dp[i][j] = invalid; }
| ^
main.cpp:15:39: error: ‘dp’ was not declared in this scope
15 | for(int j=s[i]+1; j<=s[n]; j++) { dp[i][j] = invalid; }
| ^~
main.cpp:17:29: error: ‘dp’ was not declared in this scope
17 | for(int i=0; i<=n; i++) { dp[i][0] = i + 1; }
| ^~
main.cpp:18:19: error: ‘s’ was not declared in this scope
18 | for(int j=0; j<=s[0]; j++) { dp[0][j] = j + 1; }
| ^
main.cpp:18:32: error: ‘dp’ was not declared in this scope
18 | for(int j=0; j<=s[0]; j++) { dp[0][j] = j + 1; }
| ^~
main.cpp:22:21: error: ‘s’ was not declared in this scope
22 | for
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 987654321;
const int invalid = -1;
int main(void) {
int n; scanf("%d", &n);
vector<int> s(n+1);
for(int i=0; i<=n; i++) { scanf("%d", &s[i]); }
vector<vector<int>> dp(n+1, vector<int>(s[n]+1));
for(int i=0; i<=n; i++) {
for(int j=0; j<=s[i]; j++) { dp[i][j] = inf; }
for(int j=s[i]+1; j<=s[n]; j++) { dp[i][j] = invalid; }
}
for(int i=0; i<=n; i++) { dp[i][0] = i + 1; }
for(int j=0; j<=s[0]; j++) { dp[0][j] = j + 1; }
// i番目の進化状態, j個の潜在能力
// dp[i番目の進化状態で][j個の潜在能力のカードを作るには] = 最低これだけ要る
for(int i=1; i<=n; i++) {
for(int j=1; j<=s[i]; j++) {
if(dp[i][j] == invalid) { continue; }
// 進化させる
if(dp[i-1][j] != invalid) {
dp[i][j] = dp[i-1][j] + 1;
}
// 強化する
for(int p=0; p<j; p++) {
dp[i][j] = min(dp[i][j], dp[i][p] + dp[i][j-1-p]);
}
}
}
for(int j=0; j<=s[n]; j++) {
printf("%d%c", dp[n][j], j==s[n]?'\n':' ');
}
return 0;
}