結果
問題 | No.484 収穫 |
ユーザー | tanzaku |
提出日時 | 2017-02-09 23:34:37 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 659 ms / 3,000 ms |
コード長 | 2,630 bytes |
コンパイル時間 | 3,419 ms |
コンパイル使用メモリ | 78,216 KB |
実行使用メモリ | 180,188 KB |
最終ジャッジ日時 | 2024-10-13 13:07:41 |
合計ジャッジ時間 | 12,241 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
36,216 KB |
testcase_01 | AC | 47 ms
36,476 KB |
testcase_02 | AC | 48 ms
36,824 KB |
testcase_03 | AC | 49 ms
36,820 KB |
testcase_04 | AC | 48 ms
36,400 KB |
testcase_05 | AC | 47 ms
36,528 KB |
testcase_06 | AC | 48 ms
36,736 KB |
testcase_07 | AC | 48 ms
36,824 KB |
testcase_08 | AC | 50 ms
36,400 KB |
testcase_09 | AC | 63 ms
37,876 KB |
testcase_10 | AC | 63 ms
37,672 KB |
testcase_11 | AC | 63 ms
37,888 KB |
testcase_12 | AC | 637 ms
179,796 KB |
testcase_13 | AC | 659 ms
180,024 KB |
testcase_14 | AC | 623 ms
180,188 KB |
testcase_15 | AC | 627 ms
180,152 KB |
testcase_16 | AC | 625 ms
179,860 KB |
testcase_17 | AC | 634 ms
180,188 KB |
testcase_18 | AC | 612 ms
180,116 KB |
testcase_19 | AC | 640 ms
180,124 KB |
testcase_20 | AC | 644 ms
180,076 KB |
testcase_21 | AC | 635 ms
180,140 KB |
testcase_22 | AC | 633 ms
179,828 KB |
testcase_23 | AC | 641 ms
179,896 KB |
ソースコード
import java.io.*; import java.util.*; class InputValidator implements Closeable { final InputStream in; final int NO_BUFFER = -2; int buffer; public InputValidator(final InputStream in) { this.in = in; buffer = NO_BUFFER; } int read() throws IOException { final int res = buffer == NO_BUFFER ? in.read() : buffer; buffer = NO_BUFFER; return res; } void unread(int ch) throws IOException { buffer = ch; } // [low, high] long nextLong(long low, long high) throws IOException { long val = 0; int ch = -1; while (true) { ch = read(); if (!Character.isDigit(ch)) break; val = val * 10 + ch - '0'; check(val <= high); } check(ch >= 0); check(val >= low); unread(ch); return val; } int nextInt(int low, int high) throws IOException { return (int)nextLong(low, high); } int[] nextInts(int n, int low, int high) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(low, high); if (i + 1 != n) space(); } newLineOrEOF(); return res; } void space() throws IOException { int ch = read(); check(ch == ' '); } void newLine() throws IOException { int ch = read(); if (ch == '\r') ch = read(); check(ch == '\n'); } void newLineOrEOF() throws IOException { int ch = read(); check(ch == '\r' || ch == '\n' || ch < 0); } void check(boolean b) { if (!b) throw new RuntimeException(); } @Override public void close() throws IOException { } } public class _483_Validate { public static void main(String[] args) throws IOException { new _483_Validate().solve(); } void solve() throws IOException { try (final InputValidator in = new InputValidator(System.in)) { // try (final Scanner in = new Scanner(System.in)) { int n = in.nextInt(1, 2000); in.newLine(); A = in.nextInts(n, 0, 1_000_000_000); 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)); } }