結果
| 問題 | 
                            No.1328 alligachi-problem
                             | 
                    
| コンテスト | |
| ユーザー | 
                             milanis48663220
                         | 
                    
| 提出日時 | 2020-12-25 01:07:28 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,872 bytes | 
| コンパイル時間 | 1,211 ms | 
| コンパイル使用メモリ | 101,996 KB | 
| 最終ジャッジ日時 | 2025-01-17 06:54:33 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 | 
| other | AC * 5 WA * 20 | 
ソースコード
#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;
        cout << -1 << endl;
        return 0;
    }
    // cout << idxb << ' ' << idxr << endl;
    for(int i : ans) cout << i+1 << ' ';
    cout << endl;
}
            
            
            
        
            
milanis48663220