結果

問題 No.484 収穫
ユーザー nebukuro09nebukuro09
提出日時 2017-05-10 17:47:30
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 103,600 KB
実行使用メモリ 134,268 KB
最終ジャッジ日時 2023-09-03 13:15:07
合計ジャッジ時間 14,222 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 RE -
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 9 ms
5,436 KB
testcase_10 AC 9 ms
4,504 KB
testcase_11 AC 9 ms
5,412 KB
testcase_12 AC 1,039 ms
133,004 KB
testcase_13 AC 1,032 ms
132,548 KB
testcase_14 AC 1,033 ms
132,496 KB
testcase_15 AC 1,028 ms
133,048 KB
testcase_16 AC 1,035 ms
133,220 KB
testcase_17 AC 1,027 ms
134,220 KB
testcase_18 AC 841 ms
134,060 KB
testcase_19 AC 969 ms
132,468 KB
testcase_20 AC 969 ms
134,268 KB
testcase_21 AC 970 ms
132,756 KB
testcase_22 AC 1,030 ms
133,976 KB
testcase_23 AC 1,025 ms
133,748 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);

    /*
      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