結果

問題 No.2148 ひとりUNO
ユーザー H3PO4H3PO4
提出日時 2022-12-20 21:14:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,338 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 78,356 KB
最終ジャッジ日時 2023-08-11 10:27:48
合計ジャッジ時間 7,907 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,540 KB
testcase_01 AC 113 ms
77,924 KB
testcase_02 AC 119 ms
77,796 KB
testcase_03 AC 118 ms
77,780 KB
testcase_04 AC 119 ms
77,832 KB
testcase_05 AC 126 ms
78,264 KB
testcase_06 AC 118 ms
77,720 KB
testcase_07 AC 119 ms
77,844 KB
testcase_08 AC 118 ms
77,860 KB
testcase_09 AC 115 ms
78,000 KB
testcase_10 AC 117 ms
78,356 KB
testcase_11 AC 116 ms
77,824 KB
testcase_12 AC 114 ms
77,820 KB
testcase_13 AC 125 ms
77,832 KB
testcase_14 AC 122 ms
77,876 KB
testcase_15 AC 120 ms
78,052 KB
testcase_16 AC 130 ms
77,664 KB
testcase_17 AC 128 ms
77,864 KB
testcase_18 AC 129 ms
77,892 KB
testcase_19 AC 130 ms
77,716 KB
testcase_20 AC 125 ms
77,760 KB
testcase_21 AC 131 ms
78,004 KB
testcase_22 AC 132 ms
77,932 KB
testcase_23 AC 130 ms
77,964 KB
testcase_24 AC 130 ms
77,828 KB
testcase_25 AC 134 ms
77,848 KB
testcase_26 AC 120 ms
77,808 KB
testcase_27 AC 116 ms
77,876 KB
testcase_28 AC 118 ms
77,752 KB
testcase_29 AC 118 ms
77,736 KB
testcase_30 AC 118 ms
77,852 KB
testcase_31 AC 123 ms
77,648 KB
testcase_32 AC 117 ms
77,788 KB
testcase_33 AC 119 ms
77,800 KB
testcase_34 AC 122 ms
77,756 KB
testcase_35 AC 127 ms
77,736 KB
testcase_36 AC 121 ms
77,860 KB
testcase_37 AC 111 ms
77,812 KB
testcase_38 AC 116 ms
77,868 KB
testcase_39 AC 69 ms
71,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.readline


def color2int(c: str):
    if c == "R":
        return 1
    elif c == "G":
        return 2
    elif c == "B":
        return 4
    raise ValueError


def solve(N, cards):
    lst = [0] * N
    used_color = 0
    for c, d in cards:
        i = color2int(c)
        lst[d] += i
        used_color |= i
    used_color_num = bin(used_color).count("1")
    ct = [0] * 8
    for x in lst:
        ct[x] += 1

    if used_color_num == 1:
        return True
    elif used_color_num == 2:
        return ct[1 | 2] or ct[1 | 4] or ct[2 | 4]
    else:
        return ((ct[1 | 2] and ct[1 | 4])
                or (ct[1 | 2] and ct[2 | 4])
                or (ct[1 | 4] and ct[2 | 4])
                or (ct[1 | 2] and ct[1 | 2 | 4])
                or (ct[1 | 4] and ct[1 | 2 | 4])
                or (ct[2 | 4] and ct[1 | 2 | 4])
                or ct[1 | 2 | 4] >= 2
                or (ct[1] + ct[1 | 2] + ct[1 | 4] == 0 and ct[1 | 2 | 4])
                or (ct[2] + ct[2 | 4] + ct[2 | 1] == 0 and ct[1 | 2 | 4])
                or (ct[4] + ct[4 | 1] + ct[4 | 2] == 0 and ct[1 | 2 | 4]))


T = int(input())
for _ in range(T):
    N = int(input())
    cards = []
    for __ in range(N):
        c, d = input().split()
        cards.append((c, int(d) - 1))
    print("YES" if solve(N, cards) else "NO")
0