結果

問題 No.1328 alligachi-problem
ユーザー commycommy
提出日時 2021-03-21 21:14:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 4,293 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 96,436 KB
実行使用メモリ 9,416 KB
最終ジャッジ日時 2024-05-02 05:09:23
合計ジャッジ時間 8,393 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 68 ms
9,312 KB
testcase_10 AC 50 ms
7,768 KB
testcase_11 AC 68 ms
9,352 KB
testcase_12 AC 67 ms
9,352 KB
testcase_13 AC 66 ms
9,344 KB
testcase_14 AC 66 ms
9,292 KB
testcase_15 AC 50 ms
7,628 KB
testcase_16 AC 70 ms
9,316 KB
testcase_17 AC 66 ms
9,356 KB
testcase_18 AC 66 ms
9,348 KB
testcase_19 AC 67 ms
9,348 KB
testcase_20 AC 67 ms
9,416 KB
testcase_21 AC 67 ms
9,296 KB
testcase_22 AC 66 ms
9,232 KB
testcase_23 AC 50 ms
7,716 KB
testcase_24 AC 52 ms
9,348 KB
testcase_25 AC 52 ms
9,408 KB
testcase_26 AC 55 ms
9,348 KB
testcase_27 AC 54 ms
9,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

// C, Y, idx
using T = tuple<char, int, int, char>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    input(n);
    vector<char> c(n), x(n);
    vector<int> y(n);
    rep(i, 0, n) {
        input(c[i], x[i], y[i]);
    }
    vector<T> Red, Blue;
    rep(i, 0, n) {
        (x[i] == 'R' ? Red : Blue).emplace_back(c[i], y[i], i, x[i]);
    }
    sort(Red.begin(), Red.end(), [&](const T &r1, const T &r2) -> bool {
        if (get<1>(r1) != get<1>(r2)) return get<1>(r1) < get<1>(r2);
        return get<0>(r1) < get<0>(r2);  // B < R
    });
    sort(Blue.begin(), Blue.end(), [&](const T &r1, const T &r2) -> bool {
        if (get<1>(r1) != get<1>(r2)) return get<1>(r1) < get<1>(r2);
        return get<0>(r1) > get<0>(r2);  // B > R
    });
    int red = 0, blue = 0;
    int ridx = 0, bidx = 0;
    vector<int> ans;
    auto process = [&](vector<T> &color, int &i) {
        if (color.size() <= i) return false;
        auto [ci, yi, idx, xi] = color[i];
        dump(idx + 1, red, blue, yi);
        if ((xi == 'R' ? red : blue) != yi) {
            return false;
        }
        (ci == 'R' ? red : blue)++;
        i++;
        dump(idx + 1);
        ans.emplace_back(idx);
        return true;
    };
    rep(i, 0, n) {
        dump(i, ridx, bidx, red, blue);
        if (Red.size() <= ridx) {
            if (!process(Blue, bidx)) {
                print("No");
                dump("a");
                return 0;
            }
        } else if (Blue.size() <= bidx) {
            if (!process(Red, ridx)) {
                print("No");
                dump("a");
                return 0;
            }
        } else {
            bool rs = get<1>(Red[ridx]) == red, bs = get<1>(Blue[bidx]) == blue;
            if (rs || bs) {
                if (rs && !bs) {
                    if (!process(Red, ridx)) {
                        print("No");
                        dump("a");
                        return 0;
                    }
                } else if (!rs && bs) {
                    if (!process(Blue, bidx)) {
                        print("No");
                        dump("a");
                        return 0;
                    }
                } else {
                    if (get<0>(Red[ridx]) == 'R') {
                        if (!process(Red, ridx)) {
                            print("No");
                            dump("a");
                            return 0;
                        }
                    } else {
                        if (!process(Blue, bidx)) {
                            print("No");
                            dump("a");
                            return 0;
                        }
                    }
                }
            } else {
                print("No");
                dump("a");
                return 0;
            }
        }
    }
    print("Yes");
    rep(i, 0, n) {
        cout << ans[i] + 1 << " \n"[i + 1 == n];
    }

    return 0;
}
0