結果

問題 No.2148 ひとりUNO
ユーザー norikamenorikame
提出日時 2022-12-07 15:40:15
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,684 bytes
コンパイル時間 6,406 ms
コンパイル使用メモリ 313,180 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-04 00:38:36
合計ジャッジ時間 8,931 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// 

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const string tar = "BGR";

int main() {
	int t0;
	cin >> t0;
	rep(i0, t0) {
		int n;
		cin >> n;
		vector<vector<bool>> cd(3, vector<bool>(n));
		rep(i, n) {
			char cti;
			int ci, di;
			cin >> cti >> di;
			ci = tar.find(cti);
			di--;
			cd[ci][di] = true;
		}
		vector<int> ids;
		rep(i, 3) if (count(all(cd[i]), true) > 0) ids.push_back(i);
		if ((int)(ids.size()) == 1) cout << "YES" << endl;
		else if ((int)(ids.size()) == 2) {
			bool ok = false;
			rep(i, n) if (cd[ids[0]][i] && cd[ids[1]][i]) {
				ok = true;
				break;
			}
			if (ok) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
			bool single = false;
			rep(i, 3) if (count(all(cd[i]), true) == 1) single = true;
			vector<vector<bool>> cd2;
			rep(i1, 3) {
				rep3(j1, i1+1, 3) {
					vector<bool> tcd(n);
					rep(i, n) if (cd[i1][i] && cd[j1][i]) tcd[i] = true;
					cd2.push_back(tcd);
				}
			}
			bool ok = false;
			rep(i1, 3) if (count(all(cd2[i1]), true) >= 1) {
				rep3(j1, i1+1, 3) if (count(all(cd2[j1]), true) >= 1) {
					int bcnt = 0;
					rep(i, n) if (cd2[i1][i] || cd2[j1][i]) ++bcnt;
					if (bcnt>=2 || (single&&bcnt==1)) {
						ok = true;
						break;
					}
				}
				if (ok) break;
			}
			if (ok) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}
0