結果

問題 No.1368 サイクルの中に眠る門松列
ユーザー ks2mks2m
提出日時 2021-01-29 21:49:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,195 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 74,468 KB
実行使用メモリ 74,880 KB
最終ジャッジ日時 2023-09-09 15:12:34
合計ジャッジ時間 7,061 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,248 KB
testcase_01 AC 43 ms
49,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 301 ms
71,876 KB
testcase_06 AC 297 ms
72,272 KB
testcase_07 AC 303 ms
72,244 KB
testcase_08 WA -
testcase_09 AC 314 ms
74,336 KB
testcase_10 AC 269 ms
74,244 KB
testcase_11 AC 267 ms
74,260 KB
testcase_12 AC 287 ms
74,668 KB
testcase_13 WA -
testcase_14 AC 296 ms
74,880 KB
testcase_15 AC 270 ms
74,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	static BufferedReader br;
	static PrintWriter pw;

	public static void main(String[] args) throws Exception {
		br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		pw = new PrintWriter(System.out);
		for (int i = 0; i < t; i++) {
			solve();
		}
		br.close();
		pw.flush();
	}

	static void solve() throws Exception {
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n + 2];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}

		long[] dp = new long[n + 3];
		for (int i = 3; i < n + 3; i++) {
			dp[i] = Math.max(dp[i], dp[i - 1]);
			dp[i] = Math.max(dp[i], dp[i - 2]);

			int[] b = new int[3];
			for (int j = 1; j <= 3; j++) {
				b[j - 1] = a[(i - j) % n];
			}
			if (check(b)) {
				dp[i] = Math.max(dp[i], dp[i - 3] + a[i - 3]);
			}
		}
		pw.println(dp[n + 2]);
	}

	static boolean check(int[] a) {
		if (a[0] != a[2]) {
			if (a[0] < a[1] && a[1] > a[2]) return true;
			if (a[0] > a[1] && a[1] < a[2]) return true;
		}
		return false;
	}
}
0