QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103604 | #6352. SPPPSPSS. | SEM_PRESSAO_pedroteosousa# | WA | 2ms | 3444kb | C++23 | 2.1kb | 2023-05-07 03:29:13 | 2023-05-07 03:29:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(v) v.begin(), v.end()
#define pb push_back
void dbg_out() { cerr << endl; }
template<typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
int n;
vector<int> sort_range (vector<int> &a, int l, int r) {
vector<int> vis (n), b = a;
for (int i = l; i <= r; i++) vis[a[i]]++;
for (int x = 0, j = l; x < n; x++) if (vis[x]) {
b[j++] = x;
}
return b;
}
void solve() {
cin >> n;
vector<int> a (n);
for (auto &u : a) cin >> u, u--;
// auto b = sort_range (a, 0, 4);
// for (auto u : b) cout << u << " ";
// cout << "\n";
auto check = [&] (int k) {
auto b = a;
if (k >= 3) b = sort_range (b, 0, k - 3);
if (n - (k - 1) >= 0) b = sort_range (b, n - (k - 1), n - 1);
b = sort_range (b, 0, k - 1);
if (is_sorted (all (b))) return true;
b = a;
if (n - (k - 2) >= 0) b = sort_range (b, n - (k - 2), n - 1);
if (k >= 2) b = sort_range (b, 0, k - 2);
b = sort_range (b, n - k, n - 1);
return is_sorted (all (b));
};
if (is_sorted (all (a))) {
cout << ".\n";
return;
}
int ini = 1, fim = n;
while (ini <= fim) {
int meio = (ini + fim) / 2;
if (check (meio)) fim = meio - 1;
else ini = meio + 1;
}
int k = ini;
auto b = a;
if (k >= 3) b = sort_range (b, 0, k - 3);
if (n - (k - 1) >= 0) b = sort_range (b, n - (k - 1), n - 1);
b = sort_range (b, 0, k - 1);
int vez = 1;
string ans = ".";
if (is_sorted (all (b))) {
while (ans.size () <= k) ans += (vez ? 'P' : 'S'), vez ^= 1;
}
else {
while (ans.size () <= k) ans += (vez ? 'S' : 'P'), vez ^= 1;
}
reverse (all (ans));
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3356kb
input:
3 1 2 3
output:
.
result:
ok OK 0 operations
Test #2:
score: 0
Accepted
time: 2ms
memory: 3376kb
input:
2 2 1
output:
SP.
result:
ok OK 2 operations
Test #3:
score: 0
Accepted
time: 2ms
memory: 3384kb
input:
9 3 2 4 1 5 6 7 9 8
output:
SPSP.
result:
ok OK 4 operations
Test #4:
score: 0
Accepted
time: 2ms
memory: 3336kb
input:
10 2 9 5 7 10 6 3 1 8 4
output:
SPSPSPSP.
result:
ok OK 8 operations
Test #5:
score: 0
Accepted
time: 0ms
memory: 3444kb
input:
13 9 8 5 4 3 2 1 13 12 11 10 7 6
output:
PSPSPSPS.
result:
ok OK 8 operations
Test #6:
score: 0
Accepted
time: 1ms
memory: 3364kb
input:
20 17 6 15 14 4 10 18 7 13 8 2 12 1 19 20 3 11 16 5 9
output:
SPSPSPSPSPSPSP.
result:
ok OK 14 operations
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3428kb
input:
100 98 85 81 18 27 10 68 48 19 2 55 51 61 20 91 54 35 22 83 75 8 5 17 23 21 95 37 15 92 50 78 82 44 39 26 87 52 66 70 74 89 4 59 40 12 88 86 43 14 80 53 46 63 3 36 97 60 58 57 96 11 67 99 41 34 47 71 72 73 79 9 94 6 1 77 25 31 7 45 100 90 32 24 13 76 16 93 38 29 69 42 84 30 28 33 56 49 62 64 65
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSP.
result:
wrong answer Jury (57) found answer better than participant (63)