結果
問題 | No.1328 alligachi-problem |
ユーザー |
👑 ![]() |
提出日時 | 2020-12-25 00:54:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 300 ms / 2,000 ms |
コード長 | 1,653 bytes |
コンパイル時間 | 2,711 ms |
コンパイル使用メモリ | 209,288 KB |
最終ジャッジ日時 | 2025-01-17 06:52:05 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include<bits/stdc++.h>using namespace std;using LL=long long;using ULL=unsigned long long;#define rep(i,n) for(int i=0; i<(n); i++)const string colors = "RB";int colorid(char c){ return colors.find(c); }struct Ball{ int c,x,y,i; };struct BallCmp{int c;bool operator()(const Ball& l,const Ball& r)const{if(l.y!=r.y) return l.y<r.y;return (l.c^c) > (r.c^c);}};struct graph{int N;vector<vector<int>> E;graph(int n){ N=n; E.resize(N); }void add_edge(int u,int v){ E[u].push_back(v); }vector<int> topological(){vector<int> I(N);rep(u,N) for(int v:E[u]) I[v]++;queue<int> Q;rep(i,N) if(I[i]==0) Q.push(i);vector<int> res;while(Q.size()){int q=Q.front(); Q.pop();res.push_back(q);for(int e:E[q]){I[e]--; if(I[e]==0) Q.push(e);}}if(res.size()!=N) return vector<int>();return move(res);}};int main(){int N; cin>>N;vector<Ball> D[2];rep(i,N){ char c,x; int y; cin>>c>>x>>y; D[colorid(x)].push_back({colorid(c),colorid(x),y,i}); }rep(i,2) sort(D[i].begin(),D[i].end(),BallCmp{i});graph G(N);rep(i,2) rep(j,(int)D[i].size()-1) G.add_edge(D[i][j].i,D[i][j+1].i);vector<int> P[2][2];rep(i,2) for(Ball& b:D[i]) P[i][b.c].push_back(b.i);rep(x,2){int p=0;auto& tg = P[x^1][x];for(Ball& b:D[x]){if(p>b.y || b.y-p>tg.size()){ cout<<"No"<<endl; return 0; }if(b.y-p-1>=0) G.add_edge(tg[b.y-p-1],b.i);if(b.y-p<tg.size()) G.add_edge(b.i,tg[b.y-p]);if(b.c==x) p++;}}auto Q = G.topological();if(Q.empty()){ cout<<"No"<<endl; return 0; }cout<<"Yes"<<endl;rep(i,Q.size()){ if(i) cout<<" "; cout<<(Q[i]+1); } cout<<endl;return 0;}