結果
| 問題 |
No.2148 ひとりUNO
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-12-05 23:46:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 1,127 bytes |
| コンパイル時間 | 4,667 ms |
| コンパイル使用メモリ | 263,364 KB |
| 最終ジャッジ日時 | 2025-02-09 05:32:14 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 39 |
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
bool solve(){
int n;
cin>>n;
vector<vector<int>> t(3);
rep(i,n){
char c;
int v;
cin>>c>>v;
t[(c%3)].push_back(v);
}
rep(i,3)sort(t[i].begin(),t[i].end());
sort(t.begin(),t.end());
if(t[1].size()==0)return true;
if(t[0].size()==0){
rep(i,t[1].size()){
if(binary_search(t[2].begin(),t[2].end(),t[1][i]))return true;
}
return false;
}
do{
set<int> S;
rep(i,t[0].size()){
if(binary_search(t[1].begin(),t[1].end(),t[0][i]))S.insert(t[0][i]);
}
if(S.size()==0)continue;
rep(i,t[1].size()){
if(binary_search(t[2].begin(),t[2].end(),t[1][i])){
if(S.size()>=2 || t[1].size()==1)return true;
if((*S.begin())!=t[1][i])return true;
}
}
}
while(next_permutation(t.begin(),t.end()));
return false;
}
int main(){
int _t;
cin>>_t;
rep(_,_t){
if(solve())cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
沙耶花