結果

問題 No.2148 ひとりUNO
ユーザー ThetaTheta
提出日時 2022-12-05 18:55:20
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 2,003 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-10-12 15:56:25
合計ジャッジ時間 7,960 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    for _ in range(int(input())):
        N = int(input())
        cards = [list(input().split()) for _ in range(N)]
        r_cards = filter(lambda card: card[0] == "R", cards)
        g_cards = filter(lambda card: card[0] == "G", cards)
        b_cards = filter(lambda card: card[0] == "B", cards)
        r_nums = set(map(lambda card: int(card[1]), r_cards))
        g_nums = set(map(lambda card: int(card[1]), g_cards))
        b_nums = set(map(lambda card: int(card[1]), b_cards))

        rg_common = r_nums & g_nums
        gb_common = g_nums & b_nums
        br_common = b_nums & r_nums

        if max(map(len, (r_nums, b_nums, g_nums))) == sum(map(len, (r_nums, b_nums, g_nums))):
            print("YES")
            continue

        if len(tuple(filter(lambda elm: len(elm) >= 2, (rg_common, gb_common, br_common)))) >= 2:
            print("YES")
            continue

        if max(map(len, (rg_common, gb_common, br_common))) >= 2:
            if sum(map(len, (rg_common, gb_common, br_common))) - max(map(len, (rg_common, gb_common, br_common))) > 0:
                print("YES")
            elif min(map(len, (r_nums, b_nums, g_nums))) == 0:
                print("YES")
            else:
                print("NO")
            continue

        if max(map(len, (rg_common, gb_common, br_common))) == 1:
            if sum(map(len, (rg_common, gb_common, br_common))) == 3:
                if rg_common & gb_common:
                    if all(len(nums) > 1 for nums in (r_nums, g_nums, b_nums)):
                        print("NO")
                    else:
                        print("YES")
                else:
                    print("YES")
            elif sum(map(len, (rg_common, gb_common, br_common))) == 2:
                print("YES")
            elif min(map(len, (r_nums, b_nums, g_nums))) == 0:
                print("YES")
            else:
                print("NO")
            continue

        print("NO")


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