結果
問題 |
No.2148 ひとりUNO
|
ユーザー |
👑 ![]() |
提出日時 | 2022-12-05 00:20:17 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 2,298 bytes |
コンパイル時間 | 4,091 ms |
コンパイル使用メモリ | 127,148 KB |
最終ジャッジ日時 | 2025-02-09 05:13:14 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 39 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <atcoder/modint> #include <atcoder/dsu> using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<1000000007>; bool testcase(){ int N; cin >> N; vector<vector<int>> colors(3); rep(i,N){ char c; int d; cin >> c >> d; if(c == 'R') colors[0].push_back(d); if(c == 'G') colors[1].push_back(d); if(c == 'B') colors[2].push_back(d); } rep(c,3) sort(colors[c].begin(), colors[c].end()); colors.erase(remove_if(colors.begin(), colors.end(), [](const vector<int>& a){return a.empty();}), colors.end()); if(colors.size() == 1) return true; if(colors.size() == 2){ for(int c : colors[0]) if(binary_search(colors[1].begin(), colors[1].end(), c)) return true; return false; } rep(i,3){ if(colors[1].size() > 1){ vector<int> a0, a2; rep(c,colors[1].size()) if(binary_search(colors[0].begin(), colors[0].end(), colors[1][c])) a0.push_back(c); rep(c,colors[1].size()) if(binary_search(colors[2].begin(), colors[2].end(), colors[1][c])) a2.push_back(c); if(!a0.empty() && !a2.empty()){ if(a0.size() > 1) return true; if(a2.size() > 1) return true; if(a0 != a2) return true; } } else { vector<int> a0, a2; rep(c,colors[1].size()) if(binary_search(colors[0].begin(), colors[0].end(), colors[1][c])) a0.push_back(c); rep(c,colors[1].size()) if(binary_search(colors[2].begin(), colors[2].end(), colors[1][c])) a2.push_back(c); if(!a0.empty() && !a2.empty()) return true; } swap(colors[0], colors[1]); swap(colors[1], colors[2]); } return false; } int main(){ int T; cin >> T; rep(i,T){ auto ans = testcase(); cout << (ans ? "YES\n" : "NO\n"); } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;