結果

問題 No.1369 交換門松列・竹
ユーザー KudeKude
提出日時 2021-01-29 23:19:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,646 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 89,656 KB
最終ジャッジ日時 2023-09-09 17:05:30
合計ジャッジ時間 6,135 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,128 KB
testcase_01 AC 72 ms
71,128 KB
testcase_02 AC 74 ms
71,096 KB
testcase_03 AC 73 ms
71,104 KB
testcase_04 AC 73 ms
71,308 KB
testcase_05 AC 71 ms
71,180 KB
testcase_06 AC 72 ms
70,996 KB
testcase_07 AC 72 ms
71,132 KB
testcase_08 AC 73 ms
71,340 KB
testcase_09 AC 72 ms
71,252 KB
testcase_10 AC 71 ms
71,204 KB
testcase_11 AC 71 ms
71,364 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 308 ms
80,012 KB
testcase_15 AC 130 ms
85,896 KB
testcase_16 AC 139 ms
85,904 KB
testcase_17 AC 141 ms
86,000 KB
testcase_18 AC 142 ms
86,040 KB
testcase_19 AC 134 ms
85,844 KB
testcase_20 AC 145 ms
86,132 KB
testcase_21 AC 130 ms
85,860 KB
testcase_22 AC 142 ms
85,860 KB
testcase_23 AC 138 ms
86,116 KB
testcase_24 AC 140 ms
85,628 KB
testcase_25 AC 189 ms
78,036 KB
testcase_26 AC 198 ms
78,468 KB
testcase_27 AC 192 ms
78,740 KB
testcase_28 AC 140 ms
85,180 KB
testcase_29 AC 143 ms
85,224 KB
testcase_30 AC 97 ms
89,656 KB
testcase_31 AC 98 ms
86,500 KB
testcase_32 AC 177 ms
78,336 KB
testcase_33 AC 145 ms
85,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    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])) <= 8:
            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()
0