結果

問題 No.1369 交換門松列・竹
ユーザー ks2mks2m
提出日時 2021-01-29 22:25:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,699 bytes
コンパイル時間 3,168 ms
コンパイル使用メモリ 75,336 KB
実行使用メモリ 59,312 KB
最終ジャッジ日時 2023-09-09 15:54:47
合計ジャッジ時間 7,410 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 44 ms
49,872 KB
testcase_04 AC 45 ms
49,636 KB
testcase_05 AC 44 ms
49,560 KB
testcase_06 WA -
testcase_07 AC 45 ms
49,748 KB
testcase_08 WA -
testcase_09 AC 46 ms
49,868 KB
testcase_10 AC 45 ms
49,808 KB
testcase_11 WA -
testcase_12 AC 46 ms
49,880 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 149 ms
55,328 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 151 ms
56,532 KB
testcase_20 AC 155 ms
56,292 KB
testcase_21 AC 151 ms
55,872 KB
testcase_22 AC 150 ms
56,052 KB
testcase_23 WA -
testcase_24 AC 148 ms
56,068 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 121 ms
57,352 KB
testcase_29 AC 104 ms
57,220 KB
testcase_30 AC 210 ms
58,768 KB
testcase_31 AC 213 ms
58,844 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}

		TreeSet<Integer> set = new TreeSet<>();
		for (int i = 0; i < n - 2; i++) {
			int[] b = new int[3];
			for (int j = 0; j < 3; j++) {
				b[j] = a[i + j];
			}
			if (!check(b)) {
				set.add(i);
			}
		}
		int l = set.first();
		int r = set.last();
		if (r - l >= 3) {
			pw.println("No");
			return;
		}
		for (int i = l; i < r + 2; i++) {
			for (int j = i + 1; j < r + 3; j++) {
				int t = a[j];
				a[j] = a[i];
				a[i] = t;
				boolean flg = true;
				int e = Math.min(r + 3, n - 2);
				for (int k = Math.max(i - 2, 0); k < e; k++) {
					int[] b = new int[3];
					for (int k2 = 0; k2 < 3; k2++) {
						b[k2] = a[k + k2];
					}
					if (!check(b)) {
						flg = false;
						break;
					}
				}
				if (flg) {
					pw.println("Yes");
					return;
				}
				a[i] = a[j];
				a[j] = t;
			}
		}
		pw.println("No");
	}

	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