結果

問題 No.2148 ひとりUNO
ユーザー t33ft33f
提出日時 2022-12-08 23:26:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 453 ms / 2,000 ms
コード長 1,731 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 86,660 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 18:34:27
合計ジャッジ時間 8,871 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 37 ms
5,248 KB
testcase_02 AC 37 ms
5,376 KB
testcase_03 AC 39 ms
5,376 KB
testcase_04 AC 37 ms
5,376 KB
testcase_05 AC 36 ms
5,376 KB
testcase_06 AC 37 ms
5,376 KB
testcase_07 AC 36 ms
5,376 KB
testcase_08 AC 37 ms
5,376 KB
testcase_09 AC 38 ms
5,376 KB
testcase_10 AC 38 ms
5,376 KB
testcase_11 AC 38 ms
5,376 KB
testcase_12 AC 37 ms
5,376 KB
testcase_13 AC 37 ms
5,376 KB
testcase_14 AC 40 ms
5,376 KB
testcase_15 AC 38 ms
5,376 KB
testcase_16 AC 436 ms
5,376 KB
testcase_17 AC 432 ms
5,376 KB
testcase_18 AC 453 ms
5,376 KB
testcase_19 AC 432 ms
5,376 KB
testcase_20 AC 418 ms
5,376 KB
testcase_21 AC 425 ms
5,376 KB
testcase_22 AC 423 ms
5,376 KB
testcase_23 AC 418 ms
5,376 KB
testcase_24 AC 438 ms
5,376 KB
testcase_25 AC 450 ms
5,376 KB
testcase_26 AC 159 ms
5,376 KB
testcase_27 AC 160 ms
5,376 KB
testcase_28 AC 160 ms
5,376 KB
testcase_29 AC 160 ms
5,376 KB
testcase_30 AC 157 ms
5,376 KB
testcase_31 AC 158 ms
5,376 KB
testcase_32 AC 178 ms
5,376 KB
testcase_33 AC 183 ms
5,376 KB
testcase_34 AC 170 ms
5,376 KB
testcase_35 AC 155 ms
5,376 KB
testcase_36 AC 153 ms
5,376 KB
testcase_37 AC 149 ms
5,376 KB
testcase_38 AC 150 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <numeric>
#include <set>
#include <array>
#include <vector>
#include <iostream>
using namespace std;

constexpr int R = 0, G = 1, B = 2;

bool solve(int n, const vector<array<bool, 3>> &a) {
    int col[3] = {0, 0, 0};
    for (int c = 0; c < 3; ++c)
        for (int i = 0; i < n; ++i) if (a[i][c]) ++col[c];
    set<int> s[2][3];
    for (int c1 = 0; c1 < 3; ++c1) {
        for (int c2 = c1 + 1; c2 < 3; ++c2) {
            for (int i = 0; i < n; ++i)
                if (a[i][c1] && a[i][c2]) s[c1][c2].insert(i);
        }
    }
    for (int i = 0; i < n; ++i)
        cerr << int(a[i][0]) << int(a[i][1]) << int(a[i][2]) << '\n';
    if (const int ex_sum = int(col[0] > 0) + int(col[1] > 0) + int(col[2] > 0); ex_sum == 1)
        return true;
    else if (ex_sum == 2)
        return !s[0][1].empty() || !s[0][2].empty() || !s[1][2].empty();
    else {
        if (int(s[0][1].empty()) + int(s[0][2].empty()) + int(s[1][2].empty()) >= 2)
            return false;
        if (s[0][1].size() > 1 || s[0][2].size() > 1 || s[1][2].size() > 1)
            return true;
        set<int> t;
        if (!s[0][1].empty()) t.insert(*s[0][1].begin());
        if (!s[0][2].empty()) t.insert(*s[0][2].begin());
        if (!s[1][2].empty()) t.insert(*s[1][2].begin());
        if (t.size() > 1)
            return true;
        return int(col[0] > 1) + int(col[1] > 1) + int(col[2] > 1) < 3;
    }
}

int main() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        vector<array<bool, 3>> a(n);
        for (int i = 0; i < n; ++i) {
            char c; int d; cin >> c >> d;
            a[d - 1][c == 'R' ? R : c == 'G' ? G : B] = true;
        }
        cout << (solve(n, a) ? "YES\n" : "NO\n");
    }
}
0