QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#181176 | #6352. SPPPSPSS. | ucup-team859# | WA | 0ms | 3600kb | C++14 | 2.1kb | 2023-09-16 16:18:02 | 2023-09-16 16:18:03 |
Judging History
answer
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
using ull = unsigned long long;
using ll = long long;
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n + 1, 0), dp(n + 1, 0), p(n + 1, 0);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
p[a[i]] = i;
}
bool ok = true;
for (int i = 1; i < n && ok; ++i) {
if (a[i] > a[i + 1])
ok = false;
}
if (ok) {
cout << ".";
return;
}
dp[n] = 1;
for (int i = n - 1; i >= 1; --i) {
if (a[i] == a[i + 1] - 1)
dp[i] = dp[i + 1] + 1;
else
dp[i] = 1;
}
int mn = n + 1, mx = 1;
// case 1 -> pref x x + 1 ... x + k suf
int ans = n, ls = n, lp = 0;
for (int i = 1; i < n; ++i) {
mx = max(mx, a[i]);
mn = min(mn, a[i]);
if (mx - mn + 1 == i) {
if (a[i + 1] == i + 1) {
int dr = i + dp[i + 1];
int x = max(i, n - dr);
if (i == n - dr)
++x;
if (x < ans) {
ans = x;
lp = i;
ls = n - dr;
if (lp == ls)
++lp;
}
}
}
}
// case 2 -> pref suf
int last = 0;
for (int i = 1; i < n; ++i) {
while (p[last + 1] <= i)
++last;
int x = max(i, n - last);
if (i == n - last)
++x;
if (x < ans) {
ans = x;
lp = i;
ls = n - last;
if (lp == ls)
++lp;
}
}
// case 3 -> suf pref
last = n + 1;
for (int i = n; i > 1; --i) {
while (p[last - 1] >= i)
--last;
int x = max(n - i + 1, last - 1);
if (last - 1 == n - i + 1)
++x;
if (x < ans) {
ans = x;
lp = last - 1;
ls = n - i + 1;
if (lp == ls)
++lp;
}
}
for (int i = 1; i <= ans; ++i) {
if (i == lp)
cout << 'P';
else
cout << 'S';
}
cout << ".";
}
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
3 1 2 3
output:
.
result:
ok OK 0 operations
Test #2:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
2 2 1
output:
SS.
result:
ok OK 2 operations
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
9 3 2 4 1 5 6 7 9 8
output:
SSSP.
result:
ok OK 4 operations
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3556kb
input:
10 2 9 5 7 10 6 3 1 8 4
output:
SSSSSSSP.
result:
wrong answer the permutation is not sorted