結果
問題 |
No.2148 ひとりUNO
|
ユーザー |
👑 ![]() |
提出日時 | 2024-04-21 16:38:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 1,966 bytes |
コンパイル時間 | 1,093 ms |
コンパイル使用メモリ | 84,636 KB |
最終ジャッジ日時 | 2025-02-21 08:16:13 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 39 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> using namespace std; #define rep(i,n) for(int i=0; i<(int)(n); i++) 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(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; rep(i,T){ auto ans = testcase(); cout << (ans ? "YES\n" : "NO\n"); } return 0; }