結果

問題 No.2148 ひとりUNO
ユーザー HIcoderHIcoder
提出日時 2023-07-10 22:42:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 2,209 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 111,280 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-10 01:26:11
合計ジャッジ時間 3,424 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*
1が三食

R 1 2
G 1 3
B 1 5

*/
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);

bool solve(){
    int N;
    cin>>N;
    //set<int> rst,bst,gst;

   

    vector<set<int>> st(3);
    int match=0;
    for(int i=0;i<N;i++){
        char c;
        int d;
        cin>>c>>d;
        if(c=='R'){
            st[0].insert(d);

            //rst.insert(d);
            match|=(1<<0);
            

        }else if(c=='G'){
            st[1].insert(d);

            // gst.insert(d);
            match|=(1<<1);

        }else if(c=='B'){
            st[2].insert(d);

            // bst.insert(d);
            match|=(1<<2);

        }
    }

    if(__builtin_popcount(match)==1){
        //そもそもカードが一種類しかない
        return true;
    }else if(__builtin_popcount(match)==2){
        //カードが2種類しかない

        vector<int> cnt(N+1,0);
        for(int i=0;i<3;i++){
            for(int v:st[i]){
                cnt[v]++;
                if(cnt[v]==2){
                    return true;
                }
            }
        }

        return false;

    }
    




    vector<int> p={0,1,2};

    do{

        bool flag1=false,flag2=false;

        set<int> c1,c2;
        for(int v:st[p[0]]){
            if(st[p[1]].count(v)){
                flag1=true;
                c1.insert(v);
            }
            if(st[p[2]].count(v)){
                flag2=true;
                c2.insert(v);
            }
        }

        if(!flag1 || !flag2) continue;

        if(c1!=c2){
            return true;
        }

        if(c1==c2){
            if(c1.size()>1) return true;
            
            //c1.size()==1
            if(st[p[0]].size()==1) return true;
        }




    }while(next_permutation(p.begin(),p.end()));

    return false;


}


int main(){

    int T;
    cin>>T;
    for(int t=0;t<T;t++){
        bool ans=solve();
        cout<<(ans?"YES":"NO")<<endl;
    }
}
0