結果
問題 | No.484 収穫 |
ユーザー |
![]() |
提出日時 | 2017-02-08 23:18:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 802 ms / 3,000 ms |
コード長 | 1,251 bytes |
コンパイル時間 | 3,560 ms |
コンパイル使用メモリ | 78,240 KB |
実行使用メモリ | 161,188 KB |
最終ジャッジ日時 | 2024-10-13 13:07:06 |
合計ジャッジ時間 | 15,649 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class _483 { public static void main(String[] args) throws IOException { new _483().solve(); } void solve() throws IOException { try (final Scanner in = new Scanner(System.in)) { int n = in.nextInt(); A = new int[n]; for (int i = 0; i < n; i++) { A[i] = in.nextInt(); } memo = new int[n][n][2]; for (int[][] me : memo) for (int[] mo : me) Arrays.fill(mo, -1); int ans = INF; for (int i = 0; i < n; i++) { ans = Math.min(ans, rec(i, i, 0)); } System.out.println(ans); } } int[] A; final int INF = 1<<30; int[][][] memo; int rec(int l, int r, int lr) { if (l < 0) return INF; if (r >= A.length) return INF; if (r - l + 1 == A.length) return A[lr == 0 ? l : r]; if (memo[l][r][lr] != -1) return memo[l][r][lr]; final int x = lr == 0 ? l : r; int ans = INF; ans = Math.min(ans, (rec(l - 1, r, 0) + x - l + 1)); ans = Math.min(ans, (rec(l, r + 1, 1) + r - x + 1)); ans = Math.max(A[x], ans); return memo[l][r][lr] = ans; } // for debug static void dump(Object... o) { System.err.println(Arrays.deepToString(o)); } }