結果
| 問題 |
No.2148 ひとりUNO
|
| コンテスト | |
| ユーザー |
t33f
|
| 提出日時 | 2022-12-08 23:26:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 502 ms / 2,000 ms |
| コード長 | 1,731 bytes |
| コンパイル時間 | 842 ms |
| コンパイル使用メモリ | 83,116 KB |
| 最終ジャッジ日時 | 2025-02-09 06:33:32 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 39 |
ソースコード
#include <numeric>
#include <set>
#include <array>
#include <vector>
#include <iostream>
using namespace std;
constexpr int R = 0, G = 1, B = 2;
bool solve(int n, const vector<array<bool, 3>> &a) {
int col[3] = {0, 0, 0};
for (int c = 0; c < 3; ++c)
for (int i = 0; i < n; ++i) if (a[i][c]) ++col[c];
set<int> s[2][3];
for (int c1 = 0; c1 < 3; ++c1) {
for (int c2 = c1 + 1; c2 < 3; ++c2) {
for (int i = 0; i < n; ++i)
if (a[i][c1] && a[i][c2]) s[c1][c2].insert(i);
}
}
for (int i = 0; i < n; ++i)
cerr << int(a[i][0]) << int(a[i][1]) << int(a[i][2]) << '\n';
if (const int ex_sum = int(col[0] > 0) + int(col[1] > 0) + int(col[2] > 0); ex_sum == 1)
return true;
else if (ex_sum == 2)
return !s[0][1].empty() || !s[0][2].empty() || !s[1][2].empty();
else {
if (int(s[0][1].empty()) + int(s[0][2].empty()) + int(s[1][2].empty()) >= 2)
return false;
if (s[0][1].size() > 1 || s[0][2].size() > 1 || s[1][2].size() > 1)
return true;
set<int> t;
if (!s[0][1].empty()) t.insert(*s[0][1].begin());
if (!s[0][2].empty()) t.insert(*s[0][2].begin());
if (!s[1][2].empty()) t.insert(*s[1][2].begin());
if (t.size() > 1)
return true;
return int(col[0] > 1) + int(col[1] > 1) + int(col[2] > 1) < 3;
}
}
int main() {
int t; cin >> t;
while (t--) {
int n; cin >> n;
vector<array<bool, 3>> a(n);
for (int i = 0; i < n; ++i) {
char c; int d; cin >> c >> d;
a[d - 1][c == 'R' ? R : c == 'G' ? G : B] = true;
}
cout << (solve(n, a) ? "YES\n" : "NO\n");
}
}
t33f