結果

問題 No.1328 alligachi-problem
ユーザー tkmst201tkmst201
提出日時 2020-12-26 16:47:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 2,464 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 208,904 KB
実行使用メモリ 31,680 KB
最終ジャッジ日時 2023-10-25 00:33:43
合計ジャッジ時間 13,903 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 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 202 ms
30,640 KB
testcase_10 AC 153 ms
29,604 KB
testcase_11 AC 200 ms
30,656 KB
testcase_12 AC 201 ms
30,656 KB
testcase_13 AC 201 ms
30,660 KB
testcase_14 AC 201 ms
30,660 KB
testcase_15 AC 156 ms
29,604 KB
testcase_16 AC 203 ms
30,652 KB
testcase_17 AC 201 ms
30,644 KB
testcase_18 AC 202 ms
30,652 KB
testcase_19 AC 201 ms
30,648 KB
testcase_20 AC 200 ms
30,660 KB
testcase_21 AC 208 ms
30,660 KB
testcase_22 AC 203 ms
30,652 KB
testcase_23 AC 156 ms
29,604 KB
testcase_24 AC 182 ms
31,680 KB
testcase_25 AC 186 ms
31,668 KB
testcase_26 AC 158 ms
28,948 KB
testcase_27 AC 157 ms
28,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

/*
(X[i],C[i]) と書くと、
同一の Y[i] に対して、
(赤,青)^*,(赤,赤)
(青,赤)^*,(青,青)
の順序である必要がある。

(赤,青) と (青,赤) が同時に存在する場合 No

現在構成中の赤の個数を R, 青の個数を B としたとき、X[i] = 'R' かつ Y[i] = R, Y[j] = 'B' かつ X[j] = B であるような i, j について考える
上記の考察により、次に置くべき候補である i, j はそれぞれ高々 1 通りにできる。
片方が存在しなければ置き方は決まるので ok

i = (赤,赤), j = (青,青) ならば任意の順番
i = (赤,青), j = (青,青) ならば j, i
i = (赤,赤), j = (青,赤) ならば i, j
それ以外 No
*/

int main() {
	int N;
	cin >> N;
	vector<int> C(N), X(N), Y(N);
	vector<vector<int>> ev[2][2]; // [X[i]][C[i]] [Y[i]]
	REP(i, 2) REP(j, 2) ev[i][j].resize(N);
	REP(i, N) {
		string c, x;
		cin >> c >> x >> Y[i];
		C[i] = c[0] == 'R';
		X[i] = x[0] == 'R';
		ev[X[i]][C[i]][Y[i]].emplace_back(i);
	}
	
	vector<int> ans;
	if (![&]() -> bool {
		int cnt[2] {};
		auto pset = [&](int p) -> bool {
			if (cnt[X[p]] != Y[p]) return false;
			ans.emplace_back(p);
			++cnt[C[p]];
			return true;
		};
		
		while (ans.size() < N) {
			int i = ev[1][0][cnt[1]].empty() ? (ev[1][1][cnt[1]].empty() ? -1 : ev[1][1][cnt[1]].back()) : ev[1][0][cnt[1]].back();
			int j = ev[0][1][cnt[0]].empty() ? (ev[0][0][cnt[0]].empty() ? -1 : ev[0][0][cnt[0]].back()) : ev[0][1][cnt[0]].back();
			
			int t;
			if (i == -1 && j == -1) return false;
			else if (i == -1) t = j;
			else if (j == -1) t = i;
			else if (X[i] == C[i]) t = i;
			else if (X[j] == C[j]) t = j;
			else t = i;
			ev[X[t]][C[t]][Y[t]].pop_back();
			
			pset(t);
		}
		return true;
	}()) {
		puts("No");
		return 0;
	}
	
	puts("Yes");
	REP(i, N) printf("%d%c", ans[i] + 1, " \n"[i + 1 == N]);
}
0