結果
| 問題 |
No.2148 ひとりUNO
|
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2022-12-03 13:56:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 38 ms / 2,000 ms |
| コード長 | 1,987 bytes |
| コンパイル時間 | 2,114 ms |
| コンパイル使用メモリ | 203,252 KB |
| 最終ジャッジ日時 | 2025-02-09 04:45:18 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 39 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const string colors = "RGBY";
void test(int t) {
int N;
cin >> N;
vector< int > C(N), D(N);
for (int i = 0; i < N; i++) {
char c;
cin >> c >> D[i];
C[i] = colors.find(c);
}
vector< int > cnt(1 << 4);
{
map< int, int > mp;
for (int i = 0; i < N; i++) {
mp[D[i]] |= 1 << C[i];
}
for (auto &p: mp) {
cnt[p.second]++;
}
}
for(int i = 0; i < 4; i++) {
cnt[1 << i] = min(cnt[1 << i], 1);
}
auto get_only = [&](int bit) {
if(bit == 1 or bit == 2 or bit == 4 or bit == 8) return bit;
return 0;
};
auto end = [&](int only)-> bool {
for(int i = 0; i < 4; i++) {
if((~only >> i) & 1) {
for(int j = 0; j < (1 << 4); j++) {
if(cnt[j] > 0 and ((j >> i) & 1)) {
return false;
}
}
}
}
return true;
};
auto dfs = [&](auto &dfs, int depth, int now, int last, int only) -> bool {
if(last) cnt[last]++;
if(end(only)) return true;
if(last) cnt[last]--;
if(depth >= 11) return false;
for(int i = 0; i < 4; i++) {
if((last >> i) & 1) {
if(dfs(dfs, depth + 1, i, last ^ (1 << i), only)) {
return true;
}
}
}
if(last) cnt[last]++;
for(int i = 1; i < (1 << 4); i++) {
if(cnt[i] > 0 and ((i >> now) & 1)) {
cnt[i]--;
if(dfs(dfs, depth + 1, now, i ^ (1 << now), only | get_only(i))) {
return true;
}
cnt[i]++;
}
}
if(last) cnt[last]--;
return false;
};
for(int i = 1; i < (1 << 4); i++) {
if(cnt[i] > 0) {
cnt[i]--;
for(int j = 0; j < 4; j++) {
if((i >> j) & 1) {
if (dfs(dfs, 1, j, i ^ (1 << j), get_only(i))) {
cout << "YES" << endl;
return;
}
}
}
cnt[i]++;
}
}
cout << "NO" << endl;
}
int main() {
int T;
cin >> T;
for(int t = 1; t <= T; t++) {
test(t);
}
}
ei1333333