結果
| 問題 | No.3510 RPS Eliminations |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2026-04-18 20:27:35 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 131 ms / 2,000 ms |
| コード長 | 2,415 bytes |
| 記録 | |
| コンパイル時間 | 3,138 ms |
| コンパイル使用メモリ | 367,200 KB |
| 実行使用メモリ | 46,840 KB |
| 最終ジャッジ日時 | 2026-04-18 20:27:47 |
| 合計ジャッジ時間 | 7,664 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 28 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
ll k;
int ans[200010];
VI inners;
VVI g;
int f(int i, int j) {
return (i + 1) % 3 == j ? i : j;
}
int solve(int u, array<ll, 3> d) {
if (g[u].empty()) {
int p = 0;
while (p < 2 && k >= d[p]) k -= d[p++];
ans[u] = p;
return p;
}
ll rcnt = 1LL << min(inners[g[u][1]], 60);
array<ll, 3> nd{};
rep(i, 3) rep(j, 3) if (i != j) {
ll tmp;
nd[i] = __builtin_add_overflow(nd[i], __builtin_mul_overflow(d[f(i, j)], rcnt, &tmp) ? 1LL << 60 : tmp, &tmp) ? 1LL << 60 : tmp;
}
int i = solve(g[u][0], nd);
rep(j, 3) nd[j] = i == j ? 0LL : d[f(i, j)];
int j = solve(g[u][1], nd);
return f(i, j);
}
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
ll k0;
cin >> n >> k0;
k0--;
VI a(n - 1);
rep(i, n - 1) cin >> a[i], a[i]--;
g.assign(n, VI{});
inners.assign(n, 0);
VI id(n);
rep(i, n) id[i] = i;
segtree<int, [](int x, int y) { return x + y; }, []() { return 0; }> seg(VI(n, 1));
rep(i, n - 1) {
int p = seg.max_right(0, [&](int x) { return x <= a[i]; });
int q = seg.max_right(0, [&](int x) { return x <= a[i] + 1; });
g.push_back({id[p], id[q]});
inners.emplace_back(inners[id[p]] + inners[id[q]] + 1);
id[p] = ssize(g) - 1;
seg.set(q, 0);
}
int r = id[seg.max_right(0, [](int x) { return x <= 0; })];
// 012 <-> PRS
for (int c : {1, 0, 2}) {
array<ll, 3> d{};
d[c] = 1;
k = k0;
int res = solve(r, d);
if (k) {
cout << -1 << '\n';
continue;
}
assert(res == c);
rep(i, n) cout << "PRS"[ans[i]];
cout << '\n';
}
}
}
Kude