結果

問題 No.1328 alligachi-problem
ユーザー first_vilfirst_vil
提出日時 2020-11-26 09:08:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,862 bytes
コンパイル時間 2,360 ms
コンパイル使用メモリ 207,880 KB
最終ジャッジ日時 2025-01-16 05:49:30
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 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>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);
    tuple<char, int, int> unit('?', 1000000, -1);
    for (int r = 0, b = 0, r_idx = 0, b_idx = 0; r_idx < wf_red.size() || b_idx < wf_blue.size();) {
        auto [rc, ry, rnum] = (r_idx == wf_red.size() ? unit : wf_red[r_idx]);
        auto [bc, by, bnum] = (b_idx == wf_blue.size() ? unit : 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;
}
0