結果

問題 No.2148 ひとりUNO
ユーザー lddlinanlddlinan
提出日時 2023-03-23 02:12:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 3,384 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 86,636 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 19:18:46
合計ジャッジ時間 2,052 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
    bool operator()(const int& a, const int& b) {
        return a<b;
    }
};


char mk[200004];
int qq[200004];
int main() {
    int n, i, v, h=0, x3, x5, x6, x7;
    char ib[8], c;
    int cs[4];
    memset(mk, 0, sizeof(mk));
    int tc; scanf("%d", &tc); while(tc) { tc--;
        for (i=0; i<h; i++) mk[qq[i]]=0;
        scanf("%d", &n);
        cs[0]=cs[1]=cs[2]=0;
        h=0; for (i=0; i<n; i++) {
            scanf("%s %d", ib, &v);
            if (ib[0]=='B') c=0; else if (ib[0]=='G') c=1; else c=2;
            cs[c]++;
            if (mk[v]==0) qq[h++]=v; 
            mk[v]|=(1<<c);
        }
        x3=0; for (i=0; i<h; i++) if ((mk[qq[i]]&3)==3) x3++;
        x5=0; for (i=0; i<h; i++) if ((mk[qq[i]]&5)==5) x5++;
        x6=0; for (i=0; i<h; i++) if ((mk[qq[i]]&6)==6) x6++;
        x7=0; for (i=0; i<h; i++) if ((mk[qq[i]]&7)==7) x7++;
        if (cs[0]==0) {
            if (cs[1]==0||cs[2]==0) printf("YES\n");
            else {
                // 1, 2
                if (x6) printf("YES\n"); else printf("NO\n");
            }
        } else {
            if (cs[1]==0&&cs[2]==0) printf("YES\n");
            else if (cs[1]==0) {
                //0, 2
                if (x5) printf("YES\n"); else printf("NO\n");
            } else if (cs[2]==0) {
                //0, 1
                if (x3) printf("YES\n"); else printf("NO\n");
            } else {
                if (x3>1) {
                    if (x5||x6) printf("YES\n"); else printf("NO\n");
                    continue;
                }
                if (x5>1) {
                    if (x3||x6) printf("YES\n"); else printf("NO\n");
                    continue;
                }
                if (x6>1) {
                    if (x3||x5) printf("YES\n"); else printf("NO\n");
                    continue;
                }
                if (x3==0&&x5==0) { printf("NO\n"); continue; }
                if (x3==0&&x6==0) { printf("NO\n"); continue; }
                if (x5==0&&x6==0) { printf("NO\n"); continue; }
                // one link
                if (x7==0) { printf("YES\n"); continue; }
                // 0->1->2
                if (x3&&x6) {
                    if (cs[1]==1) { printf("YES\n"); continue; }
                }
                // 0->2->1
                if (x5&&x6) {
                    if (cs[2]==1) { printf("YES\n"); continue; }
                }
                // 1->0->2
                if (x3&&x5) {
                    if (cs[1]==1) { printf("YES\n"); continue; }
                }
                // 1->2->0
                if (x6&&x5) {
                    if (cs[2]==1) { printf("YES\n"); continue; }
                }
                // 2->0->1
                if (x5&&x3) {
                    if (cs[0]==1) { printf("YES\n"); continue; }
                }
                // 2->1->0
                if (x6&&x3) {
                    if (cs[1]==1) { printf("YES\n"); continue; }
                }
                printf("NO\n");
            }
        }
    }
    return 0;
}
0