結果

問題 No.2148 ひとりUNO
ユーザー wanuiwanui
提出日時 2022-12-11 01:51:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,342 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 208,660 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 03:51:19
合計ジャッジ時間 4,855 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout<<fixed<<setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
#define debug1(a) { cerr<<#a<<":"<<a<<endl; }
#define debug2(a,b) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<endl; }
#define debug3(a,b,c) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<endl; }
#define debug4(a,b,c,d) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<" "<<#d<<":"<<d<<endl; }
// clang-format on

bool solve() {
    ll N;
    cin >> N;
    vector<vector<ll>> colors(3, vector<ll>(N + 1));
    unordered_set<ll> colorset;
    for (ll i = 0; i < N; i++) {
        char c;
        ll d;
        cin >> c >> d;
        ll cc = 0;
        if (c == 'R') cc = 0;
        if (c == 'G') cc = 1;
        if (c == 'B') cc = 2;
        colorset.insert(cc);
        colors[cc][d]++;
    }
    vector<ll> kinds(8);
    for (ll i = 1; i <= N; i++) {
        ll kind = 0;
        for (ll c = 0; c < 3; c++) {
            if (colors[c][i]) {
                kind += 1 << c;
            }
        }
        kinds[kind]++;
    }
    ll one = (kinds[1] > 0) + (kinds[2] > 0) + (kinds[4] > 0);
    ll two = (kinds[3] > 0) + (kinds[5] > 0) + (kinds[6] > 0);
    ll three = (kinds[7] > 0);
    ll all_color = colorset.size();
    if (all_color == 1) {
        return true;
    }
    if (all_color == 2) {
        if (two) return true;
        return false;
    }
    if (three) {
        if (two) return true;
        if (kinds[7] >= 2) return true;
        if (one <= 2) return true;
        return false;
    }
    if (two >= 2) return true;

    return false;
}
int main() {
    ioinit();
    ll T;
    cin >> T;
    while (T--) {
        print(solve() ? "YES" : "NO");
    }

    return 0;
}
0