結果

問題 No.1328 alligachi-problem
ユーザー milanis48663220milanis48663220
提出日時 2020-12-25 01:14:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 2,902 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 106,200 KB
実行使用メモリ 22,548 KB
最終ジャッジ日時 2023-10-21 16:07:04
合計ジャッジ時間 7,561 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,324 KB
testcase_01 AC 4 ms
8,324 KB
testcase_02 AC 4 ms
8,324 KB
testcase_03 AC 4 ms
8,320 KB
testcase_04 AC 4 ms
8,472 KB
testcase_05 AC 4 ms
8,512 KB
testcase_06 AC 4 ms
8,480 KB
testcase_07 AC 5 ms
8,524 KB
testcase_08 AC 4 ms
8,388 KB
testcase_09 AC 118 ms
22,284 KB
testcase_10 AC 51 ms
20,576 KB
testcase_11 AC 120 ms
22,296 KB
testcase_12 AC 116 ms
22,280 KB
testcase_13 AC 120 ms
22,548 KB
testcase_14 AC 124 ms
22,300 KB
testcase_15 AC 52 ms
20,584 KB
testcase_16 AC 124 ms
22,296 KB
testcase_17 AC 124 ms
22,312 KB
testcase_18 AC 120 ms
22,280 KB
testcase_19 AC 122 ms
22,284 KB
testcase_20 AC 119 ms
22,292 KB
testcase_21 AC 118 ms
22,280 KB
testcase_22 AC 120 ms
22,324 KB
testcase_23 AC 51 ms
20,584 KB
testcase_24 AC 97 ms
22,540 KB
testcase_25 AC 95 ms
22,276 KB
testcase_26 AC 94 ms
22,280 KB
testcase_27 AC 97 ms
22,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

int n;
char c[200000], x[200000];
int y[200000];

vector<vector<int>> vr, vb;
vector<int> g[200000];

bool used[200000][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> n;
    bool ok = true;
    for(int i = 0; i < n; i++) {
        cin >> c[i] >> x[i] >> y[i];
        int ci = c[i] == 'R' ? 0 : 1;
        int xi = x[i] == 'R' ? 0 : 1;
        if(ci == xi){
            if(used[y[i]][xi]) ok = false;
            used[y[i]][xi] = true;
        }
        if(x[i] == 'R'){
            int s = c[i] == 'R' ? 1 : 0;
            vr.push_back({y[i], s, i}); // (B, R, m) -> (R, R, m)の順になる
        }else{
            int s = c[i] == 'B' ? 1 : 0;
            vb.push_back({y[i], s, i}); // (R, B, m) -> (B, B, m)の順になる
        }
    }
    if(!ok){
        cout << "No" << endl;
        return 0;
    }
    sort(vr.begin(), vr.end());
    sort(vb.begin(), vb.end());
    // for(int i = 0; i+1 < (int)vr.size(); i++){
    //     int idx1 = vr[i][2], idx2 = vr[i+1][2];
    //     g[idx1].push_back(idx2);
    // }
    // for(int i = 0; i+1 < (int)vb.size(); i++){
    //     int idx1 = vb[i][2], idx2 = vb[i+1][2];
    //     g[idx1].push_back(idx2);
    // }
    int idxr = 0, idxb = 0;
    int cntr = 0, cntb = 0;
    vector<int> ans;
    // cout << vr.size() << ' ' << vb.size() << endl;
    while(idxr < vr.size() || idxb < vb.size()){
        if(idxr < vr.size() && vr[idxr][1] == 1 && vr[idxr][0] == cntr){
            ans.push_back(vr[idxr][2]);
            idxr++;
            cntr++;
            continue;
        }
        if(idxb < vb.size() && vb[idxb][1] == 1 && vb[idxb][0] == cntb){
            ans.push_back(vb[idxb][2]);
            idxb++;
            cntb++;
            continue;
        }
        if(idxr < vr.size() && vr[idxr][0] == cntr){
            ans.push_back(vr[idxr][2]);
            idxr++;
            cntb++;
            continue;
        }
        if(idxb < vb.size() && vb[idxb][0] == cntb){
            ans.push_back(vb[idxb][2]);
            idxb++;
            cntr++;
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    // cout << idxb << ' ' << idxr << endl;
    cout << "Yes" << endl;
    for(int i = 0; i < n-1; i++) cout << ans[i]+1 << ' ';
    cout << ans[n-1]+1 << endl;
}
0