結果

問題 No.266 最終進化を目指せ
ユーザー itezpaceitezpace
提出日時 2016-05-28 12:06:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 58,964 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 18:05:45
合計ジャッジ時間 1,547 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:19: warning: ‘*as[<unknown>]’ may be used uninitialized [-Wmaybe-uninitialized]
   18 |   int dp[n+1][as[n]+1];
      |               ~~~~^

ソースコード

diff #

#include <iostream>
#include <climits>
#include <array>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  int n; cin>>n;
  int s;
  int as[n+1];

  for(int i=0; i<n+1; ++i){
    cin>>s;
    as[i]=s;
  }

  int dp[n+1][as[n]+1];
  int l=CHAR_MAX; //example large number

  for(int i=0; i<n+1; ++i){
    for(int j=0; j<as[n]+1; ++j){
      dp[i][j]=l;
    }
  }

  dp[0][0]=1;
  for(int i=0; i<as[0]+1; ++i){
    dp[0][i]=i+1;
  }

  for(int i=0; i<n+1; ++i){
    for(int j=0; j<as[i]+1; ++j){
      if(i>0) dp[i][j]=dp[i-1][j]+1;
      for(int k=0; k<j; ++k){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[i][j-1-k]);
      }
    }
  }

  for(int i=0; i<as[n]+1; ++i){
    cout<<dp[n][i]<<" ";
  }
  cout<<endl;

  return 0;
}
0