結果

問題 No.2518 Adjacent Larger
ユーザー ks2mks2m
提出日時 2023-10-27 21:44:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 1,384 bytes
コンパイル時間 2,507 ms
コンパイル使用メモリ 77,172 KB
実行使用メモリ 67,664 KB
最終ジャッジ日時 2023-10-27 21:44:18
合計ジャッジ時間 8,832 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,348 KB
testcase_01 AC 195 ms
58,612 KB
testcase_02 AC 191 ms
58,936 KB
testcase_03 AC 195 ms
58,472 KB
testcase_04 AC 188 ms
58,608 KB
testcase_05 AC 189 ms
58,948 KB
testcase_06 AC 134 ms
58,132 KB
testcase_07 AC 144 ms
57,968 KB
testcase_08 AC 150 ms
58,100 KB
testcase_09 AC 146 ms
57,808 KB
testcase_10 AC 148 ms
57,864 KB
testcase_11 AC 129 ms
57,716 KB
testcase_12 AC 142 ms
57,980 KB
testcase_13 AC 128 ms
57,684 KB
testcase_14 AC 130 ms
57,936 KB
testcase_15 AC 133 ms
57,704 KB
testcase_16 AC 232 ms
67,188 KB
testcase_17 AC 177 ms
63,476 KB
testcase_18 AC 178 ms
63,628 KB
testcase_19 AC 165 ms
61,124 KB
testcase_20 AC 184 ms
63,616 KB
testcase_21 AC 223 ms
67,456 KB
testcase_22 AC 231 ms
67,176 KB
testcase_23 AC 244 ms
67,208 KB
testcase_24 AC 234 ms
67,272 KB
testcase_25 AC 230 ms
67,120 KB
testcase_26 AC 228 ms
67,512 KB
testcase_27 AC 246 ms
67,664 KB
testcase_28 AC 227 ms
67,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		PrintWriter pw = new PrintWriter(System.out);
		label:
		for (int z = 0; z < t; z++) {
			int n = Integer.parseInt(br.readLine());
			String[] sa = br.readLine().split(" ");
			int[] a = new int[n];
			int[] c = new int[3];
			for (int i = 0; i < n; i++) {
				a[i] = Integer.parseInt(sa[i]);
				c[a[i]]++;
			}

			int sum = c[1] + c[2] * 2;
			if (sum != n || c[0] == 0 || c[2] == 0) {
				pw.println("No");
				continue;
			}

			int start = -1;
			for (int i = 0; i < n; i++) {
				if (a[i] == 2) {
					start = i;
					break;
				}
			}

			boolean up = true;
			for (int i = start + 1; i < start + n; i++) {
				int x = i % n;
				if (up) {
					if (a[x] == 0) {
						up = false;
					} else if (a[x] == 1) {
						up = true;
					} else {
						pw.println("No");
						continue label;
					}
				} else {
					if (a[x] == 0) {
						pw.println("No");
						continue label;
					} else if (a[x] == 1) {
						up = false;
					} else {
						up = true;
					}
				}
			}
			if (up) {
				pw.println("No");
			} else {
				pw.println("Yes");
			}
		}
		pw.flush();
		br.close();
	}
}
0