結果

問題 No.484 収穫
ユーザー 37zigen37zigen
提出日時 2017-02-11 14:17:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,132 ms / 3,000 ms
コード長 1,472 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 74,648 KB
実行使用メモリ 210,688 KB
最終ジャッジ日時 2023-08-28 12:56:30
合計ジャッジ時間 18,279 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,080 KB
testcase_01 AC 121 ms
55,984 KB
testcase_02 AC 121 ms
57,916 KB
testcase_03 AC 121 ms
55,940 KB
testcase_04 AC 121 ms
55,964 KB
testcase_05 AC 121 ms
56,192 KB
testcase_06 AC 124 ms
55,560 KB
testcase_07 AC 123 ms
55,892 KB
testcase_08 AC 124 ms
56,176 KB
testcase_09 AC 155 ms
57,616 KB
testcase_10 AC 153 ms
58,400 KB
testcase_11 AC 155 ms
58,144 KB
testcase_12 AC 1,128 ms
208,476 KB
testcase_13 AC 1,109 ms
208,448 KB
testcase_14 AC 1,114 ms
208,380 KB
testcase_15 AC 1,116 ms
208,556 KB
testcase_16 AC 1,109 ms
208,576 KB
testcase_17 AC 1,112 ms
208,328 KB
testcase_18 AC 1,119 ms
210,688 KB
testcase_19 AC 1,094 ms
210,060 KB
testcase_20 AC 1,106 ms
209,996 KB
testcase_21 AC 1,103 ms
209,892 KB
testcase_22 AC 1,132 ms
209,692 KB
testcase_23 AC 1,112 ms
208,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
	static int N;
	static long[] A;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = new long[N];
		for (int i = 0; i < N; ++i)
			A[i] = sc.nextLong();
		long[][][] dp = new long[N][N][2];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				for (int k = 0; k < 2; ++k)
					dp[i][j][k] = Long.MAX_VALUE / 10;
			}
		}

		long ans = Long.MAX_VALUE / 10;
		if (1 <= N - 1) {
			dp[1][N - 1][0] = A[0];
		} else
			ans = Math.min(ans, A[0]);
		if (0 <= N - 2) {
			dp[0][N - 2][1] = A[N - 1];
		} else {
			ans = Math.min(ans, A[N - 1]);
		}
		for (int len = N - 2; len >= 1; --len) {
			for (int left = 0; left < N; ++left) {
				int right = left + len - 1;
				if (right >= N)
					break;
				if (left > 0) {
					dp[left][right][0] = Math.min(dp[left - 1][right][1] + len + 1, dp[left - 1][right][0] + 1);
					dp[left][right][0] = Math.max(dp[left][right][0], A[left - 1]);
				}
				if (right + 1 < N) {
					dp[left][right][1] = Math.min(dp[left][right + 1][1] + 1, dp[left][right + 1][0] + len + 1);
					dp[left][right][1] = Math.max(dp[left][right][1], A[right + 1]);
				}
			}
		}
		for (int i = 0; i < N; ++i) {
			ans = Math.min(ans, Math.max(dp[i][i][0] + 1, A[i]));
			ans = Math.min(ans, Math.max(dp[i][i][1] + 1, A[i]));
		}
		System.out.println(ans);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0