結果
問題 | No.2148 ひとりUNO |
ユーザー |
|
提出日時 | 2022-12-09 03:42:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,909 bytes |
コンパイル時間 | 1,558 ms |
コンパイル使用メモリ | 175,136 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 18:32:35 |
合計ジャッジ時間 | 2,970 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 WA * 36 |
ソースコード
#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;}