結果

問題 No.2148 ひとりUNO
ユーザー suisensuisen
提出日時 2022-12-05 23:57:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,956 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 88,892 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 21:47:32
合計ジャッジ時間 2,594 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 6 ms
6,940 KB
testcase_02 AC 6 ms
6,944 KB
testcase_03 AC 6 ms
6,944 KB
testcase_04 AC 6 ms
6,944 KB
testcase_05 AC 6 ms
6,940 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 5 ms
6,940 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 5 ms
6,944 KB
testcase_12 AC 6 ms
6,944 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 32 ms
6,944 KB
testcase_17 AC 33 ms
6,944 KB
testcase_18 AC 33 ms
6,944 KB
testcase_19 AC 32 ms
6,944 KB
testcase_20 AC 31 ms
6,940 KB
testcase_21 AC 32 ms
6,940 KB
testcase_22 AC 32 ms
6,940 KB
testcase_23 AC 32 ms
6,940 KB
testcase_24 AC 31 ms
6,944 KB
testcase_25 AC 31 ms
6,944 KB
testcase_26 AC 12 ms
6,940 KB
testcase_27 AC 13 ms
6,940 KB
testcase_28 AC 14 ms
6,944 KB
testcase_29 AC 14 ms
6,940 KB
testcase_30 AC 12 ms
6,940 KB
testcase_31 AC 13 ms
6,944 KB
testcase_32 AC 13 ms
6,940 KB
testcase_33 AC 13 ms
6,940 KB
testcase_34 AC 12 ms
6,944 KB
testcase_35 AC 14 ms
6,944 KB
testcase_36 AC 13 ms
6,944 KB
testcase_37 AC 12 ms
6,940 KB
testcase_38 AC 13 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <array>
#include <iostream>
#include <vector>

#include <atcoder/dsu>

int main() {
    int t;
    std::cin >> t;
    while (t-- > 0) {
        int n;
        std::cin >> n;

        std::vector<std::vector<int>> nums(3);
        std::vector<std::vector<int>> cols(n);

        for (int i = 0; i < n; ++i) {
            char c;
            int d;
            std::cin >> c >> d;
            --d;

            int col = c == 'R' ? 0 : c == 'G' ? 1 : 2;
            nums[col].push_back(d);
            cols[d].push_back(col);
        }

        int c = 0;
        for (int i = 0; i < 3; ++i) {
            c += nums[i].size() != 0;
        }
        if (c == 1) {
            std::cout << "YES" << '\n';
            continue;
        }
        if (c == 2) {
            std::string ans = "NO";
            for (int i = 0; i < n; ++i) {
                if (cols[i].size() >= 2) {
                    ans = "YES";
                }
            }
            std::cout << ans << '\n';
            continue;
        }

        int cnt = 0;
        atcoder::dsu uf(3);
        for (int i = 0; i < n; ++i) {
            int siz = cols[i].size();
            for (int j = 0; j < siz - 1; ++j) {
                int c1 = cols[i][j];
                int c2 = cols[i][j + 1];
                uf.merge(c1, c2);
            }
            cnt += siz >= 2;
        }
        if (uf.groups().size() >= 2) {
            std::cout << "NO" << '\n';
            continue;
        }
        {
            bool ok = false;
            for (int i = 0; i < 3; ++i) {
                if (nums[i].size() == 1) {
                    ok = true;
                }
            }
            if (ok) {
                std::cout << "YES" << '\n';
                continue;
            }
        }

        if (cnt >= 2) {
            std::cout << "YES" << '\n';
            continue;
        } else {
            std::cout << "NO" << '\n';
            continue;
        }

    }
}
0