結果

問題 No.2148 ひとりUNO
ユーザー daiotadaiota
提出日時 2022-12-09 03:42:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,909 bytes
コンパイル時間 2,651 ms
コンパイル使用メモリ 172,208 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 19:00:24
合計ジャッジ時間 3,630 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
	int i;

	cin.tie(0);  ios_base::sync_with_stdio(false);

	int T;
	cin >> T;
	REP(tc,T){

		int N;
		cin >> N;
		vector<int> b,g,r;
		for(i=1;i<=N;i++){
			char c;
			int x;
			cin >> c >> x;
			if(c=='B') b.push_back(x);
			if(c=='G') g.push_back(x);
			if(c=='R') r.push_back(x);
		}

		int bb=b.size(),gg=g.size(),rr=r.size();

		bool f=false;

		if(bb==0 && gg==0) f=true;
		else if(gg==0 && rr==0) f=true;
		else if(rr==0 && bb==0) f=true;
		if(f){
			cout << "YES" << endl;
			continue;
		}

		sort(b.begin(),b.end());
		sort(g.begin(),g.end());
		sort(r.begin(),r.end());

		if(bb==0 && gg!=0 && rr!=0){
			REP(i,gg){
				if(binary_search(r.begin(),r.end(),g[i])){
					f=true;
					break;
				}
			}
			if(f) cout << "YES" << endl;
			else cout << "NO" << endl;
			continue;
		}

		if(bb!=0 && gg==0 && rr!=0){
			REP(i,bb){
				if(binary_search(r.begin(),r.end(),b[i])){
					f=true;
					break;
				}
			}
			if(f) cout << "YES" << endl;
			else cout << "NO" << endl;
			continue;
		}

		if(bb!=0 && gg!=0 && rr==0){
			REP(i,bb){
				if(binary_search(g.begin(),g.end(),b[i])){
					f=true;
					break;
				}
			}
			if(f) cout << "YES" << endl;
			else cout << "NO" << endl;
			continue;
		}


		if(bb==1){
			if(binary_search(g.begin(),g.end(),b[0]) && binary_search(r.begin(),r.end(),b[0])){
				f=true;
				break;
			}
			if(f) cout << "YES" << endl;
			else cout << "NO" << endl;
			continue;
		}

		if(gg==1){
			if(binary_search(b.begin(),b.end(),g[0]) && binary_search(r.begin(),r.end(),g[0])){
				f=true;
				break;
			}
			if(f) cout << "YES" << endl;
			else cout << "NO" << endl;
			continue;
		}


		if(rr==1){
			if(binary_search(b.begin(),b.end(),r[0]) && binary_search(g.begin(),g.end(),r[0])){
				f=true;
				break;
			}
			if(f) cout << "YES" << endl;
			else cout << "NO" << endl;
			continue;
		}



		int p=-1;
		REP(i,bb){
			if(binary_search(g.begin(),g.end(),b[i])){
				p=b[i];
				break;
			}
		}
		REP(i,bb){
			if(b[i]==p) continue;
			if(binary_search(r.begin(),r.end(),b[i])){
				if(p!=-1){
					f=true;
					break;
				}
			}
		}
		if(f){
			cout << "YES" << endl;
			continue;
		}

		p=-1;
		REP(i,gg){
			if(binary_search(b.begin(),b.end(),g[i])){
				p=g[i];
				break;
			}
		}
		REP(i,gg){
			if(g[i]==p) continue;
			if(binary_search(r.begin(),r.end(),g[i])){
				if(p!=-1){
					f=true;
					break;
				}
			}
		}
		if(f){
			cout << "YES" << endl;
			continue;
		}

		p=-1;
		REP(i,rr){
			if(binary_search(b.begin(),b.end(),r[i])){
				p=r[i];
				break;
			}
		}
		REP(i,rr){
			if(r[i]==p) continue;
			if(binary_search(g.begin(),g.end(),r[i])){
				if(p!=-1){
					f=true;
					break;
				}
			}
		}
		if(f){
			cout << "YES" << endl;
			continue;
		}



		cout << "NO" << endl;

	}



	return 0;
}
0