結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー |
![]() |
提出日時 | 2021-01-29 21:49:37 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,195 bytes |
コンパイル時間 | 1,960 ms |
コンパイル使用メモリ | 77,832 KB |
実行使用メモリ | 74,212 KB |
最終ジャッジ日時 | 2024-06-27 08:03:40 |
合計ジャッジ時間 | 6,884 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 WA * 5 |
ソースコード
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;}}