結果
問題 |
No.1328 alligachi-problem
|
ユーザー |
![]() |
提出日時 | 2020-12-25 14:18:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,232 bytes |
コンパイル時間 | 2,383 ms |
コンパイル使用メモリ | 209,092 KB |
最終ジャッジ日時 | 2025-01-17 07:12:06 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 TLE * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; bool isok(const vector<vector<pair<int, int>>> &q, const vector<int> &idx, int r, int b) { for (int i = 0; i < 4; i++) { int color = i % 2 == 0 ? r : b; if (idx[i] > int(q.at(i).size())) return false; if (idx[i] < int(q.at(i).size()) and q.at(i).at(idx[i]).first < color) return false; } return true; }; void dfs(const vector<vector<pair<int, int>>> &q, vector<int> v, vector<int> &ans, int n) { if (int(ans.size()) == n) return; for (int i = 0; i < 4; i++) { if (int(q.at(i).size()) == v.at(i)) continue; int r = v.at(0) + v.at(1), b = v.at(2) + v.at(3); if (i % 2 == 0) { if (q.at(i).at(v.at(i)).first != r) continue; } else { if (q.at(i).at(v.at(i)).first != b) continue; } v.at(i)++; r = v.at(0) + v.at(1); b = v.at(2) + v.at(3); if (isok(q, v, r, b)) { ans.push_back(q.at(i).at(v.at(i) - 1).second); dfs(q, v, ans, n); if (int(ans.size()) == n) return; ans.pop_back(); } v.at(i)--; } } int main() { int n; cin >> n; vector<char> c(n), x(n); vector<int> y(n); for (int i = 0; i < n; i++) { cin >> c.at(i) >> x.at(i) >> y.at(i); } vector<vector<pair<int, int>>> q(4); for (int i = 0; i < n; i++) { if (c.at(i) == 'R') { if (x.at(i) == 'R') { q.at(0).emplace_back(y.at(i), i); } else { q.at(1).emplace_back(y.at(i), i); } } else { if (x.at(i) == 'R') { q.at(2).emplace_back(y.at(i), i); } else { q.at(3).emplace_back(y.at(i), i); } } } for (int i = 0; i < 4; i++) { sort(q.at(i).begin(), q.at(i).end()); } vector<int> ans; dfs(q, vector<int>{0, 0, 0, 0}, ans, n); if (ans.empty()) { cout << "No" << endl; return 0; } cout << "Yes" << endl; for (int i = 0; i < n; i++) { cout << ans.at(i) + 1; if (i == n - 1) { cout << endl; } else { cout << " "; } } }