結果

問題 No.2148 ひとりUNO
ユーザー t33ft33f
提出日時 2022-12-08 23:26:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 495 ms / 2,000 ms
コード長 1,731 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 85,468 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-04 20:22:33
合計ジャッジ時間 10,182 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 41 ms
4,376 KB
testcase_02 AC 41 ms
4,376 KB
testcase_03 AC 42 ms
4,380 KB
testcase_04 AC 42 ms
4,376 KB
testcase_05 AC 41 ms
4,376 KB
testcase_06 AC 40 ms
4,380 KB
testcase_07 AC 42 ms
4,376 KB
testcase_08 AC 42 ms
4,380 KB
testcase_09 AC 42 ms
4,376 KB
testcase_10 AC 42 ms
4,380 KB
testcase_11 AC 41 ms
4,380 KB
testcase_12 AC 42 ms
4,376 KB
testcase_13 AC 41 ms
4,380 KB
testcase_14 AC 41 ms
4,376 KB
testcase_15 AC 41 ms
4,504 KB
testcase_16 AC 484 ms
4,380 KB
testcase_17 AC 485 ms
4,376 KB
testcase_18 AC 483 ms
4,380 KB
testcase_19 AC 495 ms
4,380 KB
testcase_20 AC 473 ms
4,380 KB
testcase_21 AC 487 ms
4,376 KB
testcase_22 AC 465 ms
4,376 KB
testcase_23 AC 476 ms
4,376 KB
testcase_24 AC 483 ms
4,380 KB
testcase_25 AC 479 ms
4,376 KB
testcase_26 AC 180 ms
4,380 KB
testcase_27 AC 184 ms
4,376 KB
testcase_28 AC 179 ms
4,376 KB
testcase_29 AC 181 ms
4,376 KB
testcase_30 AC 177 ms
4,376 KB
testcase_31 AC 176 ms
4,376 KB
testcase_32 AC 174 ms
4,380 KB
testcase_33 AC 181 ms
4,376 KB
testcase_34 AC 177 ms
4,376 KB
testcase_35 AC 177 ms
4,376 KB
testcase_36 AC 173 ms
4,380 KB
testcase_37 AC 171 ms
4,376 KB
testcase_38 AC 176 ms
4,380 KB
testcase_39 AC 1 ms
4,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