結果

問題 No.1328 alligachi-problem
ユーザー 👑 NachiaNachia
提出日時 2020-12-25 00:54:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 1,653 bytes
コンパイル時間 2,765 ms
コンパイル使用メモリ 218,476 KB
実行使用メモリ 22,500 KB
最終ジャッジ日時 2023-10-21 16:02:25
合計ジャッジ時間 11,243 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 233 ms
22,496 KB
testcase_10 AC 156 ms
18,624 KB
testcase_11 AC 242 ms
22,500 KB
testcase_12 AC 244 ms
22,496 KB
testcase_13 AC 227 ms
22,428 KB
testcase_14 AC 241 ms
22,304 KB
testcase_15 AC 158 ms
18,604 KB
testcase_16 AC 257 ms
22,320 KB
testcase_17 AC 227 ms
22,440 KB
testcase_18 AC 242 ms
22,496 KB
testcase_19 AC 243 ms
22,496 KB
testcase_20 AC 243 ms
22,300 KB
testcase_21 AC 226 ms
22,428 KB
testcase_22 AC 247 ms
22,248 KB
testcase_23 AC 161 ms
18,604 KB
testcase_24 AC 148 ms
19,064 KB
testcase_25 AC 175 ms
19,656 KB
testcase_26 AC 154 ms
21,108 KB
testcase_27 AC 160 ms
21,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0