結果

問題 No.2148 ひとりUNO
ユーザー 👑 kakel-sankakel-san
提出日時 2023-01-15 20:46:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,335 bytes
コンパイル時間 1,176 ms
コンパイル使用メモリ 66,296 KB
実行使用メモリ 28,976 KB
最終ジャッジ日時 2023-08-28 13:01:27
合計ジャッジ時間 5,947 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
22,784 KB
testcase_01 AC 69 ms
24,736 KB
testcase_02 AC 68 ms
22,624 KB
testcase_03 AC 69 ms
22,708 KB
testcase_04 AC 69 ms
22,700 KB
testcase_05 AC 69 ms
24,760 KB
testcase_06 AC 68 ms
22,584 KB
testcase_07 AC 68 ms
22,688 KB
testcase_08 AC 68 ms
22,708 KB
testcase_09 AC 68 ms
22,636 KB
testcase_10 AC 69 ms
22,684 KB
testcase_11 AC 68 ms
24,664 KB
testcase_12 AC 69 ms
24,588 KB
testcase_13 AC 69 ms
22,712 KB
testcase_14 AC 68 ms
24,632 KB
testcase_15 AC 68 ms
22,656 KB
testcase_16 AC 109 ms
28,900 KB
testcase_17 AC 110 ms
26,740 KB
testcase_18 AC 108 ms
26,752 KB
testcase_19 AC 109 ms
26,864 KB
testcase_20 AC 108 ms
28,856 KB
testcase_21 AC 107 ms
26,848 KB
testcase_22 AC 108 ms
28,892 KB
testcase_23 AC 107 ms
24,872 KB
testcase_24 AC 108 ms
28,976 KB
testcase_25 AC 107 ms
26,816 KB
testcase_26 AC 84 ms
28,864 KB
testcase_27 AC 84 ms
26,840 KB
testcase_28 AC 84 ms
28,960 KB
testcase_29 AC 84 ms
26,728 KB
testcase_30 AC 84 ms
26,704 KB
testcase_31 AC 83 ms
26,820 KB
testcase_32 AC 84 ms
28,912 KB
testcase_33 AC 83 ms
26,768 KB
testcase_34 AC 85 ms
26,724 KB
testcase_35 AC 83 ms
26,752 KB
testcase_36 AC 85 ms
28,708 KB
testcase_37 AC 85 ms
26,820 KB
testcase_38 AC 84 ms
26,652 KB
testcase_39 AC 63 ms
22,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = int.Parse(ReadLine());
        var ans = new bool[t];
        for (var u = 0; u < t; ++u)
        {
            var n = int.Parse(ReadLine());
            var map = SList(n);
            ans[u] = Uno(n, map);
        }
        WriteLine(string.Join("\n", ans.Select(f => f ? "YES" : "NO")));
    }
    static bool Uno(int n, string[] map)
    {
        var b = new HashSet<int>();
        var g = new HashSet<int>();
        var r = new HashSet<int>();
        foreach (var card in map)
        {
            var d = int.Parse(card.Substring(2));
            if (card[0] == 'B') b.Add(d);
            else if (card[0] == 'G') g.Add(d);
            else r.Add(d);
        }
        return Check(b, g, r) || Check(b, r, g) || Check(r, b, g) || Check(r, g, b) || Check(g, b, r) || Check(g, r, b);
    }
    static bool Check(HashSet<int> list1, HashSet<int> list2, HashSet<int> list3)
    {
        if (list2.Count == 1)
        {
            if (list3.Count == 0)
            {
                foreach (var li in list2) if (list1.Contains(li)) return true;
            }
            else
            {
                foreach (var li in list2) if (list1.Contains(li) && list3.Contains(li)) return true;
            }
        }
        else if (list2.Count == 0)
        {
            if (list3.Count == 0) return true;
        }
        else
        {
            var f12 = new HashSet<int>();
            var f23 = new HashSet<int>();
            foreach (var li in list2)
            {
                if (list1.Contains(li)) f12.Add(li);
                if (list3.Contains(li)) f23.Add(li);
            }
            if (list3.Count == 0 && f12.Count > 0) return true;
            if (list3.Count > 0)
            {
                foreach (var f2 in f12) if (f23.Count - (f23.Contains(f2) ? 1 : 0) > 0) return true;
            }
        }
        return false;
    }
}
0