結果

問題 No.2148 ひとりUNO
ユーザー ei1333333ei1333333
提出日時 2022-12-04 11:23:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,675 bytes
コンパイル時間 1,972 ms
コンパイル使用メモリ 206,680 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 04:59:01
合計ジャッジ時間 4,094 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

const string COLORS = "BGR";

int main() {
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    vector< int > C(N), D(N);
    int type = 0;
    for (int i = 0; i < N; i++) {
      char c;
      cin >> c >> D[i];
      --D[i];
      C[i] = COLORS.find(c);
      type |= 1 << C[i];
    }
    type = __builtin_popcount(type);
    if(type == 1) {
      cout << "YES" << endl;
    } else if(type == 2) {
      sort(D.begin(), D.end());
      D.erase(unique(D.begin(), D.end()), D.end());
      if(D.size() != N) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else {
      vector< int > perm{0, 1, 2};
      bool yes = false;
      do {
        vector< int > bit(N);
        vector< int > sz(3);
        for (int i = 0; i < N; i++) {
          bit[D[i]] |= 1 << perm[C[i]];
          sz[perm[C[i]]]++;
        }
        {
          vector< int > dp(4);
          dp[0] = 1;
          for(int i = 0; i < N; i++) {
            vector< int > nxt = dp;
            for(int j = 0; j < 4; j++) {
              if ((bit[i] & 0b110) == 0b110) {
                nxt[j | 1] |= dp[j];
              }
              if ((bit[i] & 0b011) == 0b011) {
                nxt[j | 2] |= dp[j];
              }
            }
            dp = nxt;
          }
          yes |= dp[3];
        }
        {
          bool all = false;
          for(auto& p : bit) all |= p == 0b111;
          yes |= all and sz[1] == 1;
        }
      } while (next_permutation(perm.begin(), perm.end()));
      if(yes) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
  }
}
0