結果
問題 | No.1328 alligachi-problem |
ユーザー | t33f |
提出日時 | 2020-12-25 23:28:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 1,853 bytes |
コンパイル時間 | 1,222 ms |
コンパイル使用メモリ | 104,236 KB |
最終ジャッジ日時 | 2025-01-17 07:25:43 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <algorithm> #include <tuple> #include <vector> #include <cmath> #include <iostream> using namespace std; int main() { int n; cin >> n; vector<tuple<int, char, int> > R, B; for (int i = 0; i < n; i++) { char c, x; int y; cin >> c >> x >> y; if (x == 'R') R.emplace_back(y, c, i); else B.emplace_back(y, c, i); } sort(R.begin(), R.end(), [](auto lhs, auto rhs) { int y1 = get<0>(lhs), y2 = get<0>(rhs); char c1 = get<1>(lhs), c2 = get<1>(rhs); return y1 < y2 || (y1 == y2 && c1 == 'B' && c2 == 'R'); }); sort(B.begin(), B.end(), [](auto lhs, auto rhs) { int y1 = get<0>(lhs), y2 = get<0>(rhs); char c1 = get<1>(lhs), c2 = get<1>(rhs); return y1 < y2 || (y1 == y2 && c1 == 'R' && c2 == 'B'); }); int r = 0, b = 0; vector<int> ans; auto itR = R.begin(), itB = B.begin(); auto put = [&](char c, int i) { if (c == 'B') b++; else r++; ans.push_back(i); }; auto NO = [] { cout << "No" << endl; exit(0); }; while (itR != R.end() || itB != B.end()) { if (itR == R.end()) { auto [y, c, i] = *itB; if (y == b) put(c, i); else NO(); itB++; } else if (itB == B.end()) { auto [y, c, i] = *itR; if (y == r) put(c, i); else NO(); itR++; } else { auto [y1, c1, i1] = *itR; auto [y2, c2, i2] = *itB; if (y1 != r && y2 != b) NO(); else if (y1 != r) { put(c2, i2); itB++; } else if (y2 != b) { put(c1, i1); itR++; } else if (c1 == 'B') { put(c2, i2); itB++; } else { put(c1, i1); itR++; } } } cout << "Yes\n"; for (int i = 0; i < n; i++) cout << ans[i]+1 << (i < n-1 ? ' ' : '\n'); }