結果
| 問題 |
No.484 収穫
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-10 17:48:27 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 948 ms / 3,000 ms |
| コード長 | 1,338 bytes |
| コンパイル時間 | 1,008 ms |
| コンパイル使用メモリ | 117,932 KB |
| 実行使用メモリ | 133,500 KB |
| 最終ジャッジ日時 | 2024-06-12 19:07:38 |
| 合計ジャッジ時間 | 12,396 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
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;
}