結果

問題 No.2148 ひとりUNO
ユーザー roarisroaris
提出日時 2022-12-10 03:15:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,419 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 82,944 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2024-04-22 23:37:55
合計ジャッジ時間 7,303 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,352 KB
testcase_01 AC 128 ms
77,044 KB
testcase_02 AC 125 ms
76,624 KB
testcase_03 AC 128 ms
76,852 KB
testcase_04 AC 117 ms
76,672 KB
testcase_05 AC 127 ms
77,064 KB
testcase_06 AC 124 ms
77,428 KB
testcase_07 AC 121 ms
76,592 KB
testcase_08 AC 120 ms
76,428 KB
testcase_09 AC 121 ms
76,676 KB
testcase_10 AC 128 ms
77,180 KB
testcase_11 AC 115 ms
76,800 KB
testcase_12 AC 123 ms
77,048 KB
testcase_13 AC 126 ms
76,716 KB
testcase_14 AC 120 ms
76,508 KB
testcase_15 AC 125 ms
77,116 KB
testcase_16 AC 175 ms
77,440 KB
testcase_17 AC 175 ms
77,056 KB
testcase_18 AC 190 ms
77,120 KB
testcase_19 AC 201 ms
77,312 KB
testcase_20 AC 180 ms
77,028 KB
testcase_21 AC 179 ms
76,800 KB
testcase_22 AC 163 ms
77,056 KB
testcase_23 AC 179 ms
76,800 KB
testcase_24 AC 172 ms
77,056 KB
testcase_25 AC 199 ms
77,308 KB
testcase_26 AC 161 ms
77,136 KB
testcase_27 AC 154 ms
76,928 KB
testcase_28 AC 151 ms
76,740 KB
testcase_29 AC 133 ms
77,260 KB
testcase_30 AC 138 ms
76,748 KB
testcase_31 AC 154 ms
76,872 KB
testcase_32 AC 152 ms
76,948 KB
testcase_33 AC 152 ms
76,928 KB
testcase_34 AC 153 ms
76,904 KB
testcase_35 AC 155 ms
77,056 KB
testcase_36 AC 178 ms
77,312 KB
testcase_37 AC 152 ms
76,672 KB
testcase_38 AC 168 ms
77,184 KB
testcase_39 AC 42 ms
52,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from itertools import *

for _ in range(int(input())):
    N = int(input())
    L = [[] for _ in range(3)]
    
    for _ in range(N):
        C, D = input().split()
        D = int(D)
        
        if C=='R':
            L[0].append(D)
        elif C=='G':
            L[1].append(D)
        else:
            L[2].append(D)
    
    x = 3-[len(L[0]), len(L[1]), len(L[2])].count(0)
    
    if x==1:
        print('YES')
    elif x==2:
        l = [i for i in range(3) if len(L[i])>0]
        
        if len(set(L[l[0]])&set(L[l[1]]))>0:
            print('YES')
        else:
            print('NO')
    else:
        ok = False
        
        for p in permutations(range(3)):
            if len(L[p[1]])==1:
                if L[p[1]][0] in L[p[0]] and L[p[1]][0] in L[p[2]]:
                    ok = True
            else:
                s1 = set(L[p[0]])&set(L[p[1]])
                s2 = set(L[p[1]])&set(L[p[2]])
                
                if len(s2)==0:
                    continue
                elif len(s2)>1:
                    if len(s1)>0:
                        ok = True
                else:
                    if len(s1)==1 and list(s1)[0]!=list(s2)[0]:
                        ok = True
                    elif len(s1)>1:
                        ok = True
        
        if ok:
            print('YES')
        else:
            print('NO')
0