結果
問題 | No.1328 alligachi-problem |
ユーザー |
|
提出日時 | 2020-11-25 21:28:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 2,573 bytes |
コンパイル時間 | 2,504 ms |
コンパイル使用メモリ | 208,960 KB |
最終ジャッジ日時 | 2025-01-16 05:39:36 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h>using namespace std;using VI = vector<int>;#define FOR(i,a,n) for(int i=(a);i<(n);++i)#define fSORT(a,f) sort(a.begin(),a.end(),f)#define all(a) a.begin(),a.end()#define tp(a,i) get<i>(a)inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }template<class T>inline void print(const T& a) { cout << a << "\n"; }template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }int main() {init();int n; cin >> n;vector<tuple<char, int, int>> wf_red, wf_blue;FOR(i, 0, n) {char c, x; int y; cin >> c >> x >> y;if (x == 'R')wf_red.emplace_back(c, y, i);else wf_blue.emplace_back(c, y, i);}fSORT(wf_red, [](auto a, auto b) {if (tp(a, 1) == tp(b, 1))return tp(a, 0) < tp(b, 0); return tp(a, 1) < tp(b, 1); });fSORT(wf_blue, [](auto a, auto b) {if (tp(a, 1) == tp(b, 1))return tp(a, 0) > tp(b, 0); return tp(a, 1) < tp(b, 1); });VI ans;ans.reserve(n);for (int r = 0, b = 0, r_idx = 0, b_idx = 0; r_idx < wf_red.size() || b_idx < wf_blue.size();) {if (r_idx == wf_red.size()) {auto [bc, by, bnum] = wf_blue[b_idx];if (by == b) {++b_idx;ans.emplace_back(bnum + 1);if (bc == 'R')++r;else ++b;continue;}}else if (b_idx == wf_blue.size()) {auto [rc, ry, rnum] = wf_red[r_idx];if (ry == r) {++r_idx;ans.emplace_back(rnum + 1);if (rc == 'R')++r;else ++b;continue;}}else {auto [rc, ry, rnum] = wf_red[r_idx];auto [bc, by, bnum] = wf_blue[b_idx];if (ry == r && b + (rc == 'B') <= by) {++r_idx;ans.emplace_back(rnum + 1);if (rc == 'R')++r;else ++b;continue;}if (by == b && r + (bc == 'R') <= ry) {++b_idx;ans.emplace_back(bnum + 1);if (bc == 'R')++r;else ++b;continue;}}print("No");return 0;}print("Yes");print(ans);return 0;}