結果

問題 No.2148 ひとりUNO
ユーザー ygd.ygd.
提出日時 2022-12-05 23:10:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,677 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 78,380 KB
最終ジャッジ日時 2024-04-20 21:14:07
合計ジャッジ時間 8,252 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,016 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 167 ms
77,696 KB
testcase_27 AC 195 ms
77,568 KB
testcase_28 AC 170 ms
77,312 KB
testcase_29 AC 169 ms
77,696 KB
testcase_30 AC 166 ms
78,080 KB
testcase_31 AC 165 ms
77,824 KB
testcase_32 AC 165 ms
77,568 KB
testcase_33 AC 162 ms
77,568 KB
testcase_34 AC 169 ms
77,952 KB
testcase_35 AC 167 ms
77,952 KB
testcase_36 AC 156 ms
77,312 KB
testcase_37 AC 164 ms
77,568 KB
testcase_38 AC 170 ms
78,080 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
        # 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:
                # [R1,G1,B1,B2]ならいける
                if N <= 4:
                    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