結果

問題 No.2148 ひとりUNO
ユーザー 👑 NachiaNachia
提出日時 2024-04-21 16:38:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,966 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 89,136 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 16:39:01
合計ジャッジ時間 3,205 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

bool testcase(){
    int N; cin >> N;
    vector<vector<int>> colors(3);
    rep(i,N){
        char c; int d; cin >> c >> d;
        if(c == 'R') colors[0].push_back(d);
        if(c == 'G') colors[1].push_back(d);
        if(c == 'B') colors[2].push_back(d);
    }
    rep(c,3) sort(colors[c].begin(), colors[c].end());
    colors.erase(remove_if(colors.begin(), colors.end(), [](const vector<int>& a){return a.empty();}), colors.end());
    if(colors.size() == 1) return true;
    if(colors.size() == 2){
        for(int c : colors[0]) if(binary_search(colors[1].begin(), colors[1].end(), c)) return true;
        return false;
    }
    rep(i,3){
        if(colors[1].size() > 1){
            vector<int> a0, a2;
            rep(c,colors[1].size()) if(binary_search(colors[0].begin(), colors[0].end(), colors[1][c])) a0.push_back(c);
            rep(c,colors[1].size()) if(binary_search(colors[2].begin(), colors[2].end(), colors[1][c])) a2.push_back(c);
            if(!a0.empty() && !a2.empty()){
                if(a0.size() > 1) return true;
                if(a2.size() > 1) return true;
                if(a0 != a2) return true;
            }
        } else {
            vector<int> a0, a2;
            rep(c,colors[1].size()) if(binary_search(colors[0].begin(), colors[0].end(), colors[1][c])) a0.push_back(c);
            rep(c,colors[1].size()) if(binary_search(colors[2].begin(), colors[2].end(), colors[1][c])) a2.push_back(c);
            if(!a0.empty() && !a2.empty()) return true;
        }
        swap(colors[0], colors[1]);
        swap(colors[1], colors[2]);
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int T; cin >> T;
    rep(i,T){
        auto ans = testcase();
        cout << (ans ? "YES\n" : "NO\n");
    }
    return 0;
}
0