結果
問題 | No.1369 交換門松列・竹 |
ユーザー | Kude |
提出日時 | 2021-01-29 23:10:39 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,738 bytes |
コンパイル時間 | 443 ms |
コンパイル使用メモリ | 82,720 KB |
実行使用メモリ | 87,060 KB |
最終ジャッジ日時 | 2024-06-27 09:37:39 |
合計ジャッジ時間 | 4,490 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,804 KB |
testcase_01 | AC | 38 ms
53,072 KB |
testcase_02 | AC | 38 ms
53,568 KB |
testcase_03 | AC | 38 ms
52,956 KB |
testcase_04 | AC | 38 ms
52,764 KB |
testcase_05 | AC | 39 ms
53,692 KB |
testcase_06 | AC | 38 ms
53,268 KB |
testcase_07 | AC | 38 ms
53,356 KB |
testcase_08 | AC | 39 ms
52,756 KB |
testcase_09 | AC | 39 ms
52,580 KB |
testcase_10 | AC | 37 ms
53,756 KB |
testcase_11 | AC | 38 ms
53,084 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 270 ms
79,296 KB |
testcase_15 | AC | 102 ms
84,648 KB |
testcase_16 | AC | 113 ms
84,472 KB |
testcase_17 | AC | 114 ms
85,256 KB |
testcase_18 | AC | 113 ms
84,816 KB |
testcase_19 | AC | 105 ms
84,792 KB |
testcase_20 | AC | 62 ms
79,520 KB |
testcase_21 | AC | 101 ms
84,968 KB |
testcase_22 | AC | 115 ms
84,604 KB |
testcase_23 | AC | 110 ms
84,652 KB |
testcase_24 | AC | 63 ms
79,504 KB |
testcase_25 | AC | 156 ms
77,020 KB |
testcase_26 | AC | 147 ms
77,344 KB |
testcase_27 | AC | 150 ms
77,480 KB |
testcase_28 | AC | 60 ms
78,560 KB |
testcase_29 | AC | 58 ms
77,040 KB |
testcase_30 | AC | 65 ms
87,060 KB |
testcase_31 | AC | 64 ms
84,620 KB |
testcase_32 | AC | 152 ms
77,256 KB |
testcase_33 | AC | 113 ms
83,896 KB |
ソースコード
def solve(): n = int(input()) a = list(map(int, input().split())) ok = False for z in range(2): n = len(a) broken_adj = [] broken_even = [] broken_odd = [] for i in range(n - 1): d = a[i+1] - a[i] if i & 1 == 0 and d <= 0 or i & 1 == 1 and d >= 0: broken_adj.append(i) for i in range(n - 2): if a[i] == a[i+2]: if i & 1 == 0: broken_even.append(i) else: broken_odd.append(i) if max(map(len, [broken_adj, broken_even, broken_odd])) <= 4: cnt_tot = sum(map(len, [broken_adj, broken_even, broken_odd])) if broken_adj: s = broken_adj[0] t = s + 1 elif broken_even: s = broken_even[0] t = s + 2 else: s = broken_odd[0] t = s + 2 for i in (s, t): for j in range(n): if i == j: continue a[i], a[j] = a[j], a[i] for k in (i, j): if (0 <= k - 2 and a[k-2] == a[k] or k + 2 < n and a[k] == a[k+2] or k & 1 == 0 and ( 0 <= k - 1 and a[k-1] <= a[k] or k + 1 < n and a[k] >= a[k+1] ) or k & 1 == 1 and ( 0 <= k - 1 and a[k-1] >= a[k] or k + 1 < n and a[k] <= a[k+1] )): break else: ba = set(broken_adj) be = set(broken_even) bo = set(broken_odd) for k in (i, j): if k - 2 in bo: bo.remove(k - 2) if k - 2 in be: be.remove(k - 2) if k - 1 in ba: ba.remove(k - 1) if k in bo: bo.remove(k) if k in be: be.remove(k) if k in ba: ba.remove(k) if max(map(len, [ba, be, bo])) == 0: print('Yes') return a[i], a[j] = a[j], a[i] if z == 0: a = [0] + a print('No') return for _ in range(int(input())): solve()