結果

問題 No.1328 alligachi-problem
ユーザー t33ft33f
提出日時 2020-12-25 23:28:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,853 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 109,236 KB
実行使用メモリ 7,868 KB
最終ジャッジ日時 2023-10-23 23:53:40
合計ジャッジ時間 8,229 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 3 ms
4,372 KB
testcase_05 AC 3 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 4 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 127 ms
7,540 KB
testcase_10 AC 108 ms
6,188 KB
testcase_11 AC 127 ms
7,544 KB
testcase_12 AC 127 ms
7,540 KB
testcase_13 AC 127 ms
7,540 KB
testcase_14 AC 126 ms
7,472 KB
testcase_15 AC 108 ms
6,380 KB
testcase_16 AC 127 ms
7,544 KB
testcase_17 AC 126 ms
7,476 KB
testcase_18 AC 126 ms
7,540 KB
testcase_19 AC 126 ms
7,540 KB
testcase_20 AC 126 ms
7,468 KB
testcase_21 AC 126 ms
7,468 KB
testcase_22 AC 126 ms
7,480 KB
testcase_23 AC 108 ms
6,320 KB
testcase_24 AC 108 ms
7,864 KB
testcase_25 AC 109 ms
7,868 KB
testcase_26 AC 105 ms
7,468 KB
testcase_27 AC 105 ms
7,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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');
}
0