結果

問題 No.1328 alligachi-problem
ユーザー chocoruskchocorusk
提出日時 2020-12-25 00:47:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,980 bytes
コンパイル時間 4,408 ms
コンパイル使用メモリ 201,660 KB
実行使用メモリ 18,864 KB
最終ジャッジ日時 2023-10-21 16:01:19
合計ジャッジ時間 11,612 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 3 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 163 ms
11,416 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 170 ms
11,424 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 173 ms
11,424 KB
testcase_24 AC 291 ms
18,864 KB
testcase_25 AC 279 ms
17,068 KB
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    char c[200020], x[200020];
    int y[200020];
    vector<int> vr, vb;
    map<P, int> mp;
    for(int i=0; i<n; i++){
        cin>>c[i]>>x[i]>>y[i];
        if(c[i]==x[i]){
            mp[{x[i], y[i]}]++;
        }
        if(x[i]=='R') vr.push_back(i);
        else vb.push_back(i);
    }
    sort(vr.begin(), vr.end(), [&](int i, int j){
        if(y[i]!=y[j]) return y[i]<y[j];
        else return (x[i]==c[i])<(x[j]==c[j]);
    });
    sort(vb.begin(), vb.end(), [&](int i, int j){
        if(y[i]!=y[j]) return y[i]<y[j];
        else return (x[i]==c[i])<(x[j]==c[j]);
    });
    for(auto p:mp){
        if(p.second>1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    reverse(vr.begin(), vr.end());
    reverse(vb.begin(), vb.end());
    vector<int> ans;
    int cr=0, cb=0;
    for(int i=0; i<n; i++){
        if(vr.empty()){
            ans.push_back(vb.back());
            vb.pop_back();continue;
        }
        if(vb.empty()){
            ans.push_back(vr.back());
            vr.pop_back();continue;
        }
        int p=vr.back(), q=vb.back();
        if(y[p]>cr && y[q]>cb){
            cout<<"No"<<endl;
            return 0;
        }
        if(y[p]>cr){
            vb.pop_back();
            ans.push_back(q);
            if(c[q]=='R') cr++;
            else cb++;
        }else if(y[q]>cb){
            vr.pop_back();
            ans.push_back(p);
            if(c[p]=='R') cr++;
            else cb++;
        }else{
            if(x[p]==c[p]){
                vr.pop_back();
                ans.push_back(p);
                if(c[p]=='R') cr++;
                else cb++;
            }else if(x[q]==c[q]){
                vb.pop_back();
                ans.push_back(q);
                if(c[p]=='R') cr++;
                else cb++;
                cb++;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cr=0, cb=0;
    for(int i:ans){
        if(x[i]=='R'){
            if(cr!=y[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            if(cb!=y[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
        if(c[i]=='R') cr++;
        else cb++;
    }
    cout<<"Yes"<<endl;
    for(int i:ans) cout<<i+1<<" ";
    cout<<endl;
    return 0;
}
0