結果
| 問題 |
No.1328 alligachi-problem
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2020-12-25 01:02:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,171 bytes |
| コンパイル時間 | 2,274 ms |
| コンパイル使用メモリ | 205,888 KB |
| 最終ジャッジ日時 | 2025-01-17 06:53:47 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template <typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
void bad()
{
puts("No");
exit(0);
}
int main()
{
cin.tie(nullptr), ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> C(N), X(N), Y(N);
REP(i, N) {
char c, x;
cin >> c >> x >> Y[i];
C[i] = (c == 'B');
X[i] = (x == 'B');
}
const int nb = accumulate(C.begin(), C.end(), 0);
vector<int> blue(nb, -1);
vector<int> red(N - nb, -1);
vector<pint> pending_reds;
vector<pint> pending_blues;
REP(i, N) {
if (C[i] == 0) {
if (X[i]) pending_reds.emplace_back(Y[i], i);
else {
if (Y[i] >= int(red.size()) or red[Y[i]] != -1) bad();
red[Y[i]] = i;
}
} else {
if (X[i]) {
if (Y[i] >= int(blue.size()) or blue[Y[i]] != -1) bad();
blue[Y[i]] = i;
}
else pending_blues.emplace_back(Y[i], i);
}
}
sort(pending_reds.begin(), pending_reds.end());
sort(pending_blues.begin(), pending_blues.end());
{
int cur = 0;
for (auto [sz, i] : pending_blues) {
while (blue[cur] >= 0) cur++;
blue[cur] = i;
cur++;
}
}
{
int cur = 0;
for (auto [sz, i] : pending_reds) {
while (red[cur] >= 0) cur++;
red[cur] = i;
cur++;
}
}
vector<int> lo(red.size(), -1), hi(red.size(), blue.size() - 1);
REP(t, blue.size()) {
int i = blue[t];
if (X[i] == 0) {
if (Y[i] > red.size()) bad();
if (Y[i]) chmin(hi[Y[i] - 1], t - 1);
if (Y[i] < lo.size()) chmax(lo[Y[i]], t);
}
}
REP(t, red.size()) {
int i = red[t];
if (X[i] == 1) {
lo[t] = hi[t] = Y[i] - 1;
}
}
REP(i, red.size() - 1) chmax(lo[i + 1], lo[i]);
IREP(i, red.size() - 1) chmin(hi[i], hi[i + 1]);
REP(i, red.size()) if (lo[i] > hi[i]) bad();
vector<int> ret;
int ib = 0, ir = 0;
auto add = [&](int i) {
if (X[i] == 1) {
if (ib != Y[i]) bad();
} else {
if (ir != Y[i]) bad();
}
(C[i] ? ib : ir)++;
ret.emplace_back(i);
};
int cur = 0;
int now = -1;
while (now < int(blue.size())) {
while (cur < red.size() and lo[cur] == now) add(red[cur]), cur++;
now++;
if (now >= int(blue.size())) break;
add(blue[now]);
}
cout << "Yes\n";
REP(i, N) cout << ret[i] + 1 << (i + 1 == N ? '\n' : ' ');
}
hitonanode