結果

問題 No.1328 alligachi-problem
ユーザー first_vilfirst_vil
提出日時 2020-11-25 21:28:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 2,573 bytes
コンパイル時間 2,445 ms
コンパイル使用メモリ 217,124 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2023-10-19 08:39:07
合計ジャッジ時間 10,241 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 67 ms
6,520 KB
testcase_10 AC 49 ms
5,868 KB
testcase_11 AC 68 ms
6,524 KB
testcase_12 AC 68 ms
6,520 KB
testcase_13 AC 67 ms
6,520 KB
testcase_14 AC 67 ms
6,716 KB
testcase_15 AC 49 ms
6,060 KB
testcase_16 AC 67 ms
6,524 KB
testcase_17 AC 68 ms
6,720 KB
testcase_18 AC 68 ms
6,520 KB
testcase_19 AC 68 ms
6,520 KB
testcase_20 AC 68 ms
6,712 KB
testcase_21 AC 68 ms
6,712 KB
testcase_22 AC 67 ms
6,784 KB
testcase_23 AC 49 ms
6,060 KB
testcase_24 AC 50 ms
6,520 KB
testcase_25 AC 50 ms
6,712 KB
testcase_26 AC 56 ms
6,712 KB
testcase_27 AC 54 ms
6,712 KB
権限があれば一括ダウンロードができます

ソースコード

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 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;
}
0