結果

問題 No.2343 (l+r)/2
ユーザー ShirotsumeShirotsume
提出日時 2023-06-09 23:14:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,018 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 99,392 KB
最終ジャッジ日時 2023-08-30 14:24:05
合計ジャッジ時間 3,965 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
73,496 KB
testcase_01 AC 276 ms
83,436 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 145 ms
91,816 KB
testcase_05 AC 129 ms
83,824 KB
testcase_06 AC 132 ms
82,696 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 140 ms
82,784 KB
testcase_11 AC 165 ms
95,188 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 174 ms
99,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random, itertools, heapq, math
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

def solve():
    n = ii()
    a = li()

    dp = [[0, 0], [0, 0]]

    dp[a[0]][0] = 1

    for i in range(1, n):
        e = [[0, 0], [0, 0]]
        for j in range(2):
            e[a[i]][(j + 1) % 2] |= dp[1 - a[i]][j]
            e[a[i]][j] |= dp[a[i]][j]
        e[a[i]][0] |= dp[a[i]][1]
        dp = e
    if dp[0][1] or dp[1][1]:
    	print('Yes')
    	return
    a = a[::-1]
    dp = [[0, 0], [0, 0]]

    dp[a[0]][0] = 1

    for i in range(1, n):
        e = [[0, 0], [0, 0]]
        for j in range(2):
            e[a[i]][(j + 1) % 2] |= dp[1 - a[i]][j]
            e[a[i]][j] |= dp[a[i]][j]
        e[a[i]][0] |= dp[a[i]][1]
        dp = e
    print('Yes' if dp[0][1] or dp[1][1] else 'No')
        

for _ in range(ii()):
    solve()
0