結果

問題 No.484 収穫
ユーザー tanzakutanzaku
提出日時 2017-02-08 23:18:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 812 ms / 3,000 ms
コード長 1,251 bytes
コンパイル時間 4,411 ms
コンパイル使用メモリ 74,640 KB
実行使用メモリ 175,328 KB
最終ジャッジ日時 2023-08-03 16:15:52
合計ジャッジ時間 17,217 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,396 KB
testcase_01 AC 129 ms
55,836 KB
testcase_02 AC 131 ms
55,360 KB
testcase_03 AC 127 ms
55,888 KB
testcase_04 AC 130 ms
55,852 KB
testcase_05 AC 129 ms
55,728 KB
testcase_06 AC 134 ms
55,900 KB
testcase_07 AC 132 ms
55,320 KB
testcase_08 AC 132 ms
55,636 KB
testcase_09 AC 164 ms
58,132 KB
testcase_10 AC 164 ms
58,340 KB
testcase_11 AC 162 ms
57,968 KB
testcase_12 AC 803 ms
172,984 KB
testcase_13 AC 796 ms
173,272 KB
testcase_14 AC 803 ms
173,316 KB
testcase_15 AC 797 ms
175,052 KB
testcase_16 AC 812 ms
173,108 KB
testcase_17 AC 792 ms
173,428 KB
testcase_18 AC 812 ms
175,328 KB
testcase_19 AC 794 ms
171,732 KB
testcase_20 AC 805 ms
174,352 KB
testcase_21 AC 809 ms
173,916 KB
testcase_22 AC 800 ms
172,996 KB
testcase_23 AC 798 ms
173,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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));
	}
}
0