結果
問題 | No.1369 交換門松列・竹 |
ユーザー |
![]() |
提出日時 | 2021-01-29 23:03:46 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,195 bytes |
コンパイル時間 | 2,854 ms |
コンパイル使用メモリ | 75,600 KB |
実行使用メモリ | 60,212 KB |
最終ジャッジ日時 | 2023-09-09 16:48:05 |
合計ジャッジ時間 | 8,066 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,564 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 42 ms
49,852 KB |
testcase_04 | AC | 43 ms
50,024 KB |
testcase_05 | AC | 42 ms
47,588 KB |
testcase_06 | WA | - |
testcase_07 | AC | 42 ms
49,456 KB |
testcase_08 | AC | 43 ms
49,548 KB |
testcase_09 | AC | 42 ms
49,700 KB |
testcase_10 | AC | 43 ms
49,640 KB |
testcase_11 | AC | 43 ms
49,548 KB |
testcase_12 | AC | 44 ms
49,452 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 147 ms
56,280 KB |
testcase_16 | AC | 153 ms
56,216 KB |
testcase_17 | AC | 144 ms
56,856 KB |
testcase_18 | AC | 152 ms
56,564 KB |
testcase_19 | AC | 152 ms
55,848 KB |
testcase_20 | AC | 150 ms
56,120 KB |
testcase_21 | AC | 152 ms
56,928 KB |
testcase_22 | AC | 141 ms
56,084 KB |
testcase_23 | AC | 153 ms
56,128 KB |
testcase_24 | AC | 154 ms
56,676 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 121 ms
57,812 KB |
testcase_29 | AC | 120 ms
57,304 KB |
testcase_30 | AC | 194 ms
59,172 KB |
testcase_31 | AC | 215 ms
58,876 KB |
testcase_32 | WA | - |
testcase_33 | AC | 120 ms
57,800 KB |
ソースコード
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.pollFirst(); int r = l; if (!set.isEmpty()) { r = set.pollLast(); } if (!set.isEmpty()) { for (int i : set) { if (l + 4 < i && i < r - 4) { pw.println("No"); return; } } } int el = Math.min(l + 3, n); for (int i = Math.max(l - 2, 0); i < el; i++) { int er = Math.min(r + 3, n); for (int j = Math.max(r - 2, l + 1); j < er; j++) { int t = a[j]; a[j] = a[i]; a[i] = t; boolean flg = true; int e = Math.min(l + 5, n - 2); for (int k = Math.max(l - 4, 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) { e = Math.min(r + 5, n - 2); for (int k = Math.max(r - 4, 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; } }