結果
問題 | No.1369 交換門松列・竹 |
ユーザー | ks2m |
提出日時 | 2021-01-29 22:16:21 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,668 bytes |
コンパイル時間 | 2,143 ms |
コンパイル使用メモリ | 75,264 KB |
実行使用メモリ | 59,632 KB |
最終ジャッジ日時 | 2023-09-09 15:43:41 |
合計ジャッジ時間 | 7,133 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,628 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 42 ms
49,508 KB |
testcase_04 | AC | 42 ms
49,512 KB |
testcase_05 | AC | 43 ms
49,592 KB |
testcase_06 | WA | - |
testcase_07 | AC | 43 ms
49,736 KB |
testcase_08 | WA | - |
testcase_09 | AC | 43 ms
49,912 KB |
testcase_10 | AC | 42 ms
49,768 KB |
testcase_11 | WA | - |
testcase_12 | AC | 44 ms
49,536 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 150 ms
55,932 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 145 ms
55,832 KB |
testcase_20 | AC | 147 ms
55,336 KB |
testcase_21 | AC | 150 ms
56,560 KB |
testcase_22 | AC | 149 ms
55,732 KB |
testcase_23 | WA | - |
testcase_24 | AC | 150 ms
56,268 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 108 ms
56,616 KB |
testcase_29 | AC | 117 ms
56,940 KB |
testcase_30 | AC | 205 ms
58,528 KB |
testcase_31 | AC | 179 ms
58,608 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
ソースコード
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 + 2]; 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; for (int k = Math.max(i - 2, 0); k <= r; 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; } }