結果

問題 No.2148 ひとりUNO
ユーザー ygd.ygd.
提出日時 2022-12-05 23:34:30
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 2,761 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 80,556 KB
最終ジャッジ日時 2023-08-02 21:31:19
合計ジャッジ時間 11,484 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,616 KB
testcase_01 AC 230 ms
79,348 KB
testcase_02 AC 208 ms
78,956 KB
testcase_03 AC 202 ms
78,936 KB
testcase_04 AC 219 ms
79,096 KB
testcase_05 AC 210 ms
78,832 KB
testcase_06 AC 219 ms
79,228 KB
testcase_07 AC 213 ms
78,980 KB
testcase_08 AC 227 ms
79,160 KB
testcase_09 AC 228 ms
79,436 KB
testcase_10 AC 206 ms
78,932 KB
testcase_11 AC 217 ms
78,808 KB
testcase_12 AC 223 ms
79,604 KB
testcase_13 AC 218 ms
78,940 KB
testcase_14 AC 215 ms
79,036 KB
testcase_15 AC 223 ms
79,132 KB
testcase_16 AC 257 ms
78,892 KB
testcase_17 AC 256 ms
78,736 KB
testcase_18 AC 258 ms
79,684 KB
testcase_19 AC 263 ms
78,884 KB
testcase_20 AC 300 ms
80,352 KB
testcase_21 AC 290 ms
80,556 KB
testcase_22 AC 269 ms
79,256 KB
testcase_23 AC 259 ms
79,568 KB
testcase_24 AC 255 ms
79,532 KB
testcase_25 AC 274 ms
79,832 KB
testcase_26 AC 220 ms
79,808 KB
testcase_27 AC 233 ms
79,372 KB
testcase_28 AC 218 ms
78,568 KB
testcase_29 AC 222 ms
79,768 KB
testcase_30 AC 221 ms
78,712 KB
testcase_31 AC 227 ms
79,908 KB
testcase_32 AC 222 ms
79,784 KB
testcase_33 AC 224 ms
78,796 KB
testcase_34 AC 237 ms
79,488 KB
testcase_35 AC 222 ms
78,748 KB
testcase_36 AC 215 ms
79,080 KB
testcase_37 AC 222 ms
79,084 KB
testcase_38 AC 223 ms
78,692 KB
testcase_39 AC 94 ms
71,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
import math
import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
from collections import defaultdict
from collections import deque
#import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        dic = defaultdict(list)
        R = set([]); G = set([]); B = set([])
        for i in range(N):
            c,d = input().split()
            d = int(d)
            dic[d].append(c)
            if c == 'R': R.add(d)
            if c == 'G': G.add(d)
            if c == 'B': B.add(d)
        # print(R,G,B)
        RGB = set([])
        RG = set([]); GB = set([]); BR = set([])
        for v,L in dic.items():
            if len(L) == 3:
                RGB.add(v)
            elif len(L) == 2:
                if 'R' in L and 'G' in L:
                    RG.add(v)
                if 'G' in L and 'B' in L:
                    GB.add(v)
                if 'B' in L and 'R' in L:
                    BR.add(v)
        # print(RGB,RG,GB,BR)
        # 1色のみの場合
        if len(G) == len(B) == 0:
            print('YES')
        elif len(B) == len(R) == 0:
            print('YES')
        elif len(R) == len(G) == 0:
            print('YES')
        # 2色のみの場合
        elif len(R) == 0:
            if len(GB) >= 1:
                print('YES')
            else:
                print('NO')
        elif len(G) == 0:
            if len(BR) >= 1:
                print('YES')
            else:
                print('NO')
        elif len(B) == 0:
            if len(RG) >= 1:
                print('YES')
            else:
                print('NO')
        # 3色ある場合
        elif len(RGB) >= 2:
            print('YES')
        elif len(RGB) == 1:
            if len(RG) >= 1 or len(GB) >= 1 or len(BR) >= 1:
                print('YES')
            else:
                # [RN...R3,R2,R1,G1,B1,B2,B3...BN]ならいける
                if len(R) == 1 or len(G) == 1 or len(B) == 1:
                    print('YES')
                else:
                    print('NO')
        else:
            if len(RG) >= 1 and len(GB) >= 1:
                print('YES')
            elif len(GB) >= 1 and len(BR) >= 1:
                print('YES')
            elif len(BR) >= 1 and len(RG) >= 1:
                print('YES')
            else:
                print('NO')


if __name__ == '__main__':
    main()
0