結果

問題 No.484 収穫
ユーザー mamekinmamekin
提出日時 2017-04-09 15:12:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 630 ms / 3,000 ms
コード長 1,374 bytes
コンパイル時間 1,360 ms
コンパイル使用メモリ 108,480 KB
実行使用メモリ 222,336 KB
最終ジャッジ日時 2024-04-21 14:30:38
合計ジャッジ時間 9,004 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 5 ms
5,760 KB
testcase_10 AC 5 ms
5,632 KB
testcase_11 AC 4 ms
5,504 KB
testcase_12 AC 604 ms
222,208 KB
testcase_13 AC 597 ms
222,080 KB
testcase_14 AC 594 ms
222,208 KB
testcase_15 AC 585 ms
222,080 KB
testcase_16 AC 593 ms
222,208 KB
testcase_17 AC 604 ms
222,208 KB
testcase_18 AC 599 ms
222,208 KB
testcase_19 AC 612 ms
222,080 KB
testcase_20 AC 630 ms
222,208 KB
testcase_21 AC 607 ms
222,080 KB
testcase_22 AC 615 ms
222,336 KB
testcase_23 AC 611 ms
222,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    vector<vector<vector<int> > > dp(n, vector<vector<int> >(n, vector<int>(2, INF)));
    dp[0][n-1][0] = 0;
    dp[0][n-1][1] = 0;
    for(int len=n-1; len>0; --len){
        for(int i=0; i<n-len; ++i){
            int j = i + len;
            for(int k=0; k<2; ++k){
                int curr = (k == 0) ? i : j;
                int t1 = max(a[i], dp[i][j][k] + abs(curr - i)) + 1;
                dp[i+1][j][0] = min(dp[i+1][j][0], t1);
                int t2 = max(a[j], dp[i][j][k] + abs(curr - j)) + 1;
                dp[i][j-1][1] = min(dp[i][j-1][1], t2);
            }
        }
    }

    int ans = INF;
    for(int i=0; i<n; ++i){
        for(int j=0; j<2; ++j){
            ans = min(ans, max(a[i], dp[i][i][j]));
        }
    }
    cout << ans << endl;

    return 0;
}
0