結果
| 問題 |
No.2148 ひとりUNO
|
| コンテスト | |
| ユーザー |
hatsuka_iwa
|
| 提出日時 | 2023-12-03 00:49:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 1,845 bytes |
| コンパイル時間 | 2,665 ms |
| コンパイル使用メモリ | 211,812 KB |
| 最終ジャッジ日時 | 2025-02-18 06:28:27 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 39 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int T; cin >> T;
auto check = [&](vector<int> &Node, vector<vector<int>> Edge, vector<int> &Count, int All) {
int N = Node.size();
for (int i = 0; i < N - 1; i++) {
int u = Node.at(i), v = Node.at(i + 1);
if (Edge.at(u).at(v) == 0 && All == 0) return false;
else if (Edge.at(u).at(v) > 0) { Edge.at(u).at(v)--; Edge.at(v).at(u)--; }
else if (Count.at(u) != 1) All--;
}
return true;
};
auto f = [&]() {
int N, All = 0; cin >> N;
vector<int> Node, ABC(200000), Count(3);
vector Edge(3, vector<int>(3));
set<int> S;
for (int i = 0; i < N; i++) {
char C; int D; cin >> C >> D;
if (C == 'R') { ABC.at(D - 1) |= 1; Count.at(0)++; }
if (C == 'G') { ABC.at(D - 1) |= 2; Count.at(1)++; }
if (C == 'B') { ABC.at(D - 1) |= 4; Count.at(2)++; }
}
for (int i = 0; i < N; i++) {
int A = ABC.at(i);
if (A == 7) {
All++;
S.insert(0);
S.insert(1);
S.insert(2);
}
if (A == 6) {
Edge.at(1).at(2)++;
Edge.at(2).at(1)++;
S.insert(1);
S.insert(2);
}
if (A == 5) {
Edge.at(0).at(2)++;
Edge.at(2).at(0)++;
S.insert(0);
S.insert(2);
}
if (A == 4)
S.insert(2);
if (A == 3) {
Edge.at(0).at(1)++;
Edge.at(1).at(0)++;
S.insert(0);
S.insert(1);
}
if (A == 2)
S.insert(1);
if (A == 1)
S.insert(0);
}
for (int i : S) Node.push_back(i);
do {
if (check(Node, Edge, Count, All)) return true;
} while (next_permutation(Node.begin(), Node.end()));
return false;
};
for (int i = 0; i < T; i++)
cout << (f() ? "YES" : "NO") << endl;
}
hatsuka_iwa