結果

問題 No.484 収穫
ユーザー nebukuro09nebukuro09
提出日時 2017-05-10 17:48:27
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,033 ms / 3,000 ms
コード長 1,338 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 103,544 KB
実行使用メモリ 134,300 KB
最終ジャッジ日時 2023-09-03 13:15:35
合計ジャッジ時間 13,652 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 9 ms
5,764 KB
testcase_12 AC 1,024 ms
132,944 KB
testcase_13 AC 1,020 ms
133,708 KB
testcase_14 AC 1,021 ms
133,240 KB
testcase_15 AC 1,030 ms
132,956 KB
testcase_16 AC 1,033 ms
133,156 KB
testcase_17 AC 1,027 ms
134,300 KB
testcase_18 AC 838 ms
133,168 KB
testcase_19 AC 972 ms
133,264 KB
testcase_20 AC 968 ms
133,548 KB
testcase_21 AC 959 ms
132,668 KB
testcase_22 AC 1,024 ms
133,208 KB
testcase_23 AC 1,024 ms
134,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    immutable int INF = 2 * 10^^9;
    
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int);

    if (N == 1) {
        writeln(A[0]);
        return;
    }

    /*
      dp[l][r][left or right]: 
      未訪問の区間がl~rで、最後に訪問済のノードが l-1 or r+1 のときの最小コスト
     */
    auto dp = new int[][][](N, N, 2);
    foreach (i; 0..N) foreach (j; 0..N) fill(dp[i][j], INF);
    dp[1][N-1][0] = A[0];
    dp[0][N-2][1] = A[N-1];

    foreach (len; iota(N-1, 1, -1)) {
        foreach (i; 0..N-len+1) {
            int j = i + len - 1;
            int ltol = max(dp[i][j][0] + 1, A[i]);
            int rtol = max(dp[i][j][1] + j - i, A[i]);
            int ltor = max(dp[i][j][0] + j - i, A[j]);
            int rtor = max(dp[i][j][1] + 1, A[j]);
            dp[i+1][j][0] = min(dp[i+1][j][0], min(ltol, rtol));
            dp[i][j-1][1] = min(dp[i][j-1][1], min(ltor, rtor));
        }
    }

    
    int ans = INF;
    foreach (i; 0..N) {
        ans = min(ans, max(dp[i][i][0]+1, A[i]));
        ans = min(ans, max(dp[i][i][1]+1, A[i]));
    }

    ans.writeln;
}
0