結果

問題 No.484 収穫
ユーザー parukiparuki
提出日時 2017-02-13 12:44:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 3,000 ms
コード長 1,564 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 166,512 KB
実行使用メモリ 35,712 KB
最終ジャッジ日時 2024-04-21 14:29:02
合計ジャッジ時間 4,160 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 115 ms
35,456 KB
testcase_13 AC 113 ms
35,712 KB
testcase_14 AC 111 ms
35,456 KB
testcase_15 AC 112 ms
35,584 KB
testcase_16 AC 112 ms
35,584 KB
testcase_17 AC 111 ms
35,584 KB
testcase_18 AC 111 ms
35,456 KB
testcase_19 AC 115 ms
35,328 KB
testcase_20 AC 113 ms
35,584 KB
testcase_21 AC 114 ms
35,584 KB
testcase_22 AC 112 ms
35,584 KB
testcase_23 AC 112 ms
35,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int N = 2050, INF = 1 << 30;
int dp[2][N][N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vi a(n);
    rep(i, n)cin >> a[i];

    if(n == 1) {
        cout << a[0] << endl;
        return 0;
    }
    
    rep(i, 2)rep(j, n + 1)rep(k, n + 1)dp[i][j][k] = INF;

    dp[0][1][n - 1] = a[0];
    dp[1][0][n - 2] = a[n - 1];

    for(int m = n - 1; m > 1; --m) {
        rep(i, 2)for(int l=0;l+m<=n;++l) {
            int r = l + m - 1;
            int x = dp[i][l][r];
            if(x == INF)continue;
            if(i == 0) {
                smin(dp[0][l + 1][r], max(x + 1, a[l]));
                smin(dp[1][l][r - 1], max(x + r - l, a[r]));
            } else {
                smin(dp[0][l + 1][r], max(x + r - l, a[l]));
                smin(dp[1][l][r - 1], max(x + 1, a[r]));
            }
        }
    }

    int ans = INF;
    rep(i, 2)rep(j, n) if(dp[i][j][j]!=INF){
        smin(ans, max(dp[i][j][j] + 1, a[j]));
    }
    cout << ans << endl;
}
0