結果
| 問題 |
No.1328 alligachi-problem
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2020-12-25 00:29:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 2,000 ms |
| コード長 | 2,578 bytes |
| コンパイル時間 | 2,390 ms |
| コンパイル使用メモリ | 207,884 KB |
| 最終ジャッジ日時 | 2025-01-17 06:48:59 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
int tra(char c) {
return c == 'R' ? 0 : 1;
}
int main() {
int n; cin >> n;
vector ball(2, vector(n + 1, vector<int>{}));
vector<int> c(n);
REP(i, n) {
char ci, x; int y; cin >> ci >> x >> y;
c[i] = tra(ci);
ball[tra(x)][y].emplace_back(i);
}
REP(j, n) {
sort(ALL(ball[0][j]), [&](int a, int b) { return c[a] < c[b]; });
if (ball[0][j].size() >= 2 && ball[0][j][0] == 0 && ball[0][j][0] == ball[0][j][1]) {
cout << "No\n";
return 0;
}
}
REP(j, n) {
sort(ALL(ball[1][j]), [&](int a, int b) { return c[a] > c[b]; });
if (ball[1][j].size() >= 2 && ball[1][j][0] == 1 && ball[1][j][0] == ball[1][j][1]) {
cout << "No\n";
return 0;
}
}
int p[2] = {};
vector<int> ans;
while (ans.size() < n) {
if (ball[0][p[0]].empty() && ball[1][p[1]].empty()) {
cout << "No\n";
return 0;
}
if (ball[0][p[0]].empty()) {
int id = ball[1][p[1]].back();
ball[1][p[1]].pop_back();
ans.emplace_back(id);
++p[c[id]];
} else if (ball[1][p[1]].empty()) {
int id = ball[0][p[0]].back();
ball[0][p[0]].pop_back();
ans.emplace_back(id);
++p[c[id]];
} else if (c[ball[0][p[0]].back()] == 1 && c[ball[1][p[1]].back()] == 0) {
cout << "No\n";
return 0;
} else if (c[ball[0][p[0]].back()] == 0) {
int id = ball[0][p[0]].back();
ball[0][p[0]].pop_back();
ans.emplace_back(id);
++p[c[id]];
} else {
int id = ball[1][p[1]].back();
ball[1][p[1]].pop_back();
ans.emplace_back(id);
++p[c[id]];
}
}
cout << "Yes\n";
REP(i, n) cout << ans[i] + 1 << " \n"[i + 1 == n];
return 0;
}
emthrm