結果

問題 No.1328 alligachi-problem
ユーザー umezoumezo
提出日時 2020-12-25 01:05:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 2,462 bytes
コンパイル時間 2,351 ms
コンパイル使用メモリ 217,192 KB
実行使用メモリ 9,336 KB
最終ジャッジ日時 2023-10-21 16:04:11
合計ジャッジ時間 8,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 122 ms
8,816 KB
testcase_10 AC 99 ms
7,688 KB
testcase_11 AC 125 ms
8,816 KB
testcase_12 AC 127 ms
8,932 KB
testcase_13 AC 130 ms
8,820 KB
testcase_14 AC 127 ms
8,816 KB
testcase_15 AC 103 ms
7,820 KB
testcase_16 AC 130 ms
8,816 KB
testcase_17 AC 126 ms
8,820 KB
testcase_18 AC 128 ms
8,816 KB
testcase_19 AC 129 ms
8,816 KB
testcase_20 AC 125 ms
8,816 KB
testcase_21 AC 128 ms
8,816 KB
testcase_22 AC 130 ms
8,816 KB
testcase_23 AC 105 ms
7,688 KB
testcase_24 AC 102 ms
9,260 KB
testcase_25 AC 101 ms
9,336 KB
testcase_26 AC 107 ms
9,260 KB
testcase_27 AC 105 ms
9,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  
  vector<char> C(n+1),X(n+1);
  vector<int> Y(n+1);
  rep(i,n) cin>>C[i+1]>>X[i+1]>>Y[i+1];
  
  vector<pair<int,int>> RR,BB,RB,BR;
  for(int i=1;i<=n;i++){
    if(C[i]=='R' && X[i]=='R') RR.push_back({Y[i],i});
    if(C[i]=='R' && X[i]=='B') RB.push_back({Y[i],i});
    if(C[i]=='B' && X[i]=='R') BR.push_back({Y[i],i});
    if(C[i]=='B' && X[i]=='B') BB.push_back({Y[i],i});
  }
  sort(ALL(RR));
  sort(ALL(RB));
  sort(ALL(BR));
  sort(ALL(BB));
  
  queue<pair<int,int>> qrr,qrb,qbr,qbb;
  for(auto x:RR) qrr.push(x);
  for(auto x:RB) qrb.push(x);
  for(auto x:BR) qbr.push(x);
  for(auto x:BB) qbb.push(x);
  
  bool flag=true;
  int tmp=-1;
  for(auto x:RR){
    if(x.first==tmp) flag=false;
    tmp=x.first;
  }
  tmp=-1;
  for(auto x:BB){
    if(x.first==tmp) flag=false;
    tmp=x.first;
  }
  if(flag==false){
    cout<<"No"<<endl;
    return 0;
  }

  int r=0,b=0;
  vector<int> B;
  while(!qrr.empty() || !qbb.empty() || !qrb.empty() || !qbr.empty()){
    if(!qrr.empty() && qrr.front().first==r){
      if(qbr.empty() || qbr.front().first>=r+1){
        auto x=qrr.front();
        qrr.pop();
        B.push_back(x.second);
        r++;
        continue;
      }
    }
    
    if(!qbb.empty() && qbb.front().first==b){
      if(qrb.empty() || qrb.front().first>=b+1){
        auto x=qbb.front();
        qbb.pop();
        B.push_back(x.second);
        b++;
        continue;
      }
    }
    
    if(!qrb.empty() && qrb.front().first==b){
      if((qrr.empty() && qbr.empty()) || (qrr.empty() && qbr.front().first>=r+1) ||
        (qbr.empty() && qrr.front().first>=r+1) || (qbr.front().first>=r+1 && qrr.front().first>=r+1)){
        auto x=qrb.front();
        qrb.pop();
        B.push_back(x.second);
        r++;
        continue;
      }
    }
    
    if(!qbr.empty() && qbr.front().first==r){
      if((qbb.empty() && qrb.empty()) || (qbb.empty() && qrb.front().first>=b+1) ||
        (qrb.empty() && qbb.front().first>=b+1) || (qrb.front().first>=b+1 && qbb.front().first>=b+1)){
        auto x=qbr.front();
        qbr.pop();
        B.push_back(x.second);
        b++;
        continue;
      }
    }
    
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  rep(i,n){
    if(i) cout<<" ";
    cout<<B[i];
  }
  cout<<endl;
    
  return 0;
}
0