結果
| 問題 |
No.1328 alligachi-problem
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2020-12-25 01:05:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 2,000 ms |
| コード長 | 2,462 bytes |
| コンパイル時間 | 2,246 ms |
| コンパイル使用メモリ | 210,136 KB |
| 最終ジャッジ日時 | 2025-01-17 06:54:24 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#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;
}
umezo