結果
| 問題 |
No.2148 ひとりUNO
|
| コンテスト | |
| ユーザー |
ygd.
|
| 提出日時 | 2022-12-05 23:34:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 229 ms / 2,000 ms |
| コード長 | 2,761 bytes |
| コンパイル時間 | 335 ms |
| コンパイル使用メモリ | 82,164 KB |
| 実行使用メモリ | 78,368 KB |
| 最終ジャッジ日時 | 2024-10-12 19:44:25 |
| 合計ジャッジ時間 | 8,196 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 39 |
ソースコード
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()
ygd.