結果
問題 |
No.2148 ひとりUNO
|
ユーザー |
![]() |
提出日時 | 2022-12-04 11:23:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 1,675 bytes |
コンパイル時間 | 2,185 ms |
コンパイル使用メモリ | 204,660 KB |
最終ジャッジ日時 | 2025-02-09 04:55:53 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 39 |
ソースコード
#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; } } } }