結果

問題 No.2148 ひとりUNO
ユーザー ntuda
提出日時 2022-12-26 22:20:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 78,744 KB
最終ジャッジ日時 2024-11-21 08:54:52
合計ジャッジ時間 9,363 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
T = int(input())
dic = {"R":0,"G":1,"B":2}
from collections import defaultdict
dic2 = defaultdict(lambda:[0,0,0])

def ok():
    print("YES")

def ng():
    print("NO")

def solve():
    N = int(input())
    dic2 = defaultdict(lambda: [0, 0, 0])
    Y = 0
    CN = [0] * 3
    for _ in range(N):
        c,d = input().split()
        dic2[int(d)][dic[c]] += 1
        CN[dic[c]] += 1
    D = Counter(CN)
    if D[0] == 2:
        ok()
        return

    if D[0] == 1:
        for i in range(3):
            if CN[i] == 0:
                a,b = (i+1)%3, (i+2)%3
        for x in dic2.values():
            if x[a] > 0 and x[b] > 0:
                ok()
                return
        ng()
        return

    for X in dic2.values():
        D = Counter(X)
        if D[0] > 1:
            continue
        elif D[0] == 1:
            for i in range(3):
                if X[i] == 0:
                    if Y == 0 or Y == i+1:
                        Y = i+1
                    else:
                        ok()
                        return
        elif D[1] == 3:
            for i in range(3):
                if CN[i] - X[i] == 0:
                    ok()
                    return
            if Y == 0:
                Y = 4
            else:
                ok()
                return
        else:
            ok()
            return
    ng()

for i in range(T):
    solve()




0