結果

問題 No.484 収穫
ユーザー 37zigen37zigen
提出日時 2017-02-11 14:16:09
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,472 bytes
コンパイル時間 2,230 ms
コンパイル使用メモリ 74,340 KB
実行使用メモリ 210,912 KB
最終ジャッジ日時 2023-08-28 12:55:02
合計ジャッジ時間 19,024 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,700 KB
testcase_01 AC 126 ms
56,088 KB
testcase_02 AC 124 ms
55,484 KB
testcase_03 WA -
testcase_04 AC 124 ms
55,992 KB
testcase_05 AC 125 ms
56,080 KB
testcase_06 AC 131 ms
55,732 KB
testcase_07 AC 129 ms
55,752 KB
testcase_08 AC 128 ms
55,732 KB
testcase_09 AC 156 ms
57,784 KB
testcase_10 AC 155 ms
57,844 KB
testcase_11 AC 159 ms
58,020 KB
testcase_12 AC 1,165 ms
208,532 KB
testcase_13 AC 1,152 ms
208,716 KB
testcase_14 AC 1,162 ms
208,416 KB
testcase_15 AC 1,163 ms
208,572 KB
testcase_16 AC 1,168 ms
208,488 KB
testcase_17 AC 1,156 ms
210,496 KB
testcase_18 AC 1,158 ms
210,912 KB
testcase_19 AC 1,139 ms
209,868 KB
testcase_20 AC 1,149 ms
209,624 KB
testcase_21 AC 1,201 ms
209,608 KB
testcase_22 AC 1,162 ms
208,492 KB
testcase_23 AC 1,168 ms
208,448 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.max(ans, A[0]);
		if (0 <= N - 2) {
			dp[0][N - 2][1] = A[N - 1];
		} else {
			ans = Math.max(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