QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196558 | #6352. SPPPSPSS. | jrjyy | WA | 0ms | 3564kb | C++20 | 2.4kb | 2023-10-01 19:06:19 | 2023-10-01 19:06:19 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n;
std::cin >> n;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
--a[i];
}
if (std::is_sorted(a.begin(), a.end())) {
std::cout << "0\n\n";
return 0;
}
std::string ans(n, 'P');
auto work = [&]() {
int m = n / 2;
i64 sum = std::accumulate(a.begin(), a.begin() + m, 0ll);
if (sum == 1ll * m * (m - 1) / 2) {
int l = m - 1, r = m - 1;
while (l >= 0 && a[l] == l) {
--l;
}
while (r < n && a[r] == r) {
++r;
}
int x = l + 1, y = n - r, z = std::max(x, y) + (x == y);
std::string res;
if (x >= y) {
res = std::string(z - 1, 'S') + "P";
} else {
res = std::string(z - 1, 'P') + "S";
}
if (res.size() < ans.size()) {
ans = res;
}
}
std::string res;
res = std::string(m, 'P') + "S";
std::priority_queue<int> p;
std::priority_queue<int, std::vector<int>, std::greater<>> q;
for (int i = 0; i < m; ++i) {
p.push(a[i]);
}
for (int i = m; i < n; ++i) {
q.push(a[i]);
}
if (n % 2 == 0) {
q.push(p.top());
p.pop();
}
for (int i = 0; !p.empty() && p.top() >= int(p.size()); ++i) {
if (i % 2 == 0) {
res += "P";
while (p.size() < res.size()) {
p.push(q.top());
q.pop();
}
} else {
res += "S";
while (q.size() < res.size()) {
q.push(p.top());
p.pop();
}
}
}
if (res.size() < ans.size()) {
ans = res;
}
};
std::reverse(a.begin(), a.end());
for (auto &x : a) {
x = n - x - 1;
}
work();
for (auto &x : ans) {
x = "PS"[x == 'P'];
}
std::reverse(a.begin(), a.end());
for (auto &x : a) {
x = n - x - 1;
}
work();
std::cout << ans << ".\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
3 1 2 3
output:
0
result:
wrong answer Token "0" doesn't correspond to pattern "[PS]{0,1000001}."