結果

問題 No.266 最終進化を目指せ
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-07-12 05:56:29
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,116 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 51,324 KB
最終ジャッジ日時 2023-09-22 14:18:34
合計ジャッジ時間 930 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:3: error: ‘vector’ was not declared in this scope
   vector<int> s(n+1);
   ^~~~~~
main.cpp:10:3: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:3:1:
+#include <vector>
 using namespace std;
main.cpp:10:3:
   vector<int> s(n+1);
   ^~~~~~
main.cpp:10:10: error: expected primary-expression before ‘int’
   vector<int> s(n+1);
          ^~~
main.cpp:11:42: error: ‘s’ was not declared in this scope
   for(int i=0; i<=n; i++) { scanf("%d", &s[i]); }
                                          ^
main.cpp:12:17: error: expected primary-expression before ‘int’
   vector<vector<int>> dp(n+1, vector<int>(s[n]+1));
                 ^~~
main.cpp:14:21: error: ‘s’ was not declared in this scope
     for(int j=0; j<=s[i]; j++) { dp[i][j] = inf; }
                     ^
main.cpp:14:34: error: ‘dp’ was not declared in this scope
     for(int j=0; j<=s[i]; j++) { dp[i][j] = inf; }
                                  ^~
main.cpp:15:15: error: ‘s’ was not declared in this scope
     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
     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
   for(int i=0; i<=n; i++) { dp[i][0] = i + 1; }
                             ^~
main.cpp:18:19: error: ‘s’ was not declared in this scope
   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
   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
     for(int j=1; j<=s[i]; j++) {
                     ^
main.cpp:23:10: error: ‘dp’ was not declared in this scope
       if(dp[i][j] == invalid

ソースコード

diff #

#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;
}
0