結果

問題 No.1328 alligachi-problem
ユーザー chocoruskchocorusk
提出日時 2020-12-25 00:50:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 2,962 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 146,568 KB
実行使用メモリ 18,828 KB
最終ジャッジ日時 2023-10-21 16:01:40
合計ジャッジ時間 9,839 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 214 ms
12,564 KB
testcase_10 AC 173 ms
11,380 KB
testcase_11 AC 220 ms
12,588 KB
testcase_12 AC 212 ms
12,588 KB
testcase_13 AC 211 ms
12,608 KB
testcase_14 AC 214 ms
12,600 KB
testcase_15 AC 167 ms
11,388 KB
testcase_16 AC 206 ms
12,588 KB
testcase_17 AC 213 ms
12,576 KB
testcase_18 AC 208 ms
12,576 KB
testcase_19 AC 212 ms
12,604 KB
testcase_20 AC 207 ms
12,584 KB
testcase_21 AC 217 ms
12,580 KB
testcase_22 AC 212 ms
12,580 KB
testcase_23 AC 172 ms
11,388 KB
testcase_24 AC 280 ms
18,828 KB
testcase_25 AC 295 ms
18,200 KB
testcase_26 AC 183 ms
12,580 KB
testcase_27 AC 181 ms
12,580 KB
権限があれば一括ダウンロードができます

ソースコード

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>
#define popcount __builtin_popcount
using namespace std;
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++;
            }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=0; i<n; i++){
        cout<<ans[i]+1;
        if(i<n-1) cout<<" ";
    }
    cout<<endl;
    return 0;
}
0