結果

問題 No.484 収穫
ユーザー あっちむいてホイ!あっちむいてホイ!
提出日時 2021-09-27 16:08:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 3,000 ms
コード長 1,305 bytes
コンパイル時間 1,122 ms
コンパイル使用メモリ 100,088 KB
実行使用メモリ 97,256 KB
最終ジャッジ日時 2023-09-20 16:49:18
合計ジャッジ時間 3,743 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 136 ms
96,972 KB
testcase_13 AC 135 ms
96,968 KB
testcase_14 AC 136 ms
97,256 KB
testcase_15 AC 135 ms
97,056 KB
testcase_16 AC 135 ms
97,072 KB
testcase_17 AC 135 ms
96,972 KB
testcase_18 AC 134 ms
97,056 KB
testcase_19 AC 135 ms
97,012 KB
testcase_20 AC 134 ms
97,088 KB
testcase_21 AC 133 ms
97,028 KB
testcase_22 AC 134 ms
97,008 KB
testcase_23 AC 134 ms
97,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
using namespace std;
using ll = long long int;
#define chmax(x,y)  (x) = ((x) > (y)) ? (x) : ((x) = (y));
#define chmin(x,y)  (x) = ((x) < (y)) ? (x) : ((x) = (y));
const int INF = 1e9;
const ll INFL = 1e18;
const int Mod = 1e9 + 7;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};


int main(int argc, char const *argv[])
{
  int N; cin >> N;
  vector<ll> A(N); for(auto &a : A)cin >> a;
  vector<vector<vector<ll>>> dp(2,vector<vector<ll>>(N+1,vector<ll>(N+1,INFL)));
  dp[0][1][N] = A[0];
  dp[1][0][N-1] = A[N-1];
  for(int len = N;len > 0;--len)
  {
    for(int i=0;i<N;++i)
    {
      if(i+len > N)continue;
      if(i > 0)
      {
        chmin(dp[0][i+1][i+len],max(dp[0][i][i+len]+1,A[i]));
        chmin(dp[1][i][i+len-1],max(dp[0][i][i+len]+len,A[i+len-1]));
      }

      if(i+len < N)
      {
        chmin(dp[1][i][i+len-1],max(dp[1][i][i+len]+1,A[i+len-1]));
        chmin(dp[0][i+1][i+len],max(dp[1][i][i+len]+len,A[i]));
      }
    }
  }
  ll answer = INFL;
  for(int i=0;i<N;++i)
  {
    chmin(answer,min(dp[0][i][i], dp[1][i][i]));
  }
  std::cout << answer << std::endl;
}
0