QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100010 | #6352. SPPPSPSS. | Wolam | RE | 2ms | 3380kb | C++14 | 2.7kb | 2023-04-24 13:19:05 | 2023-04-24 13:19:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7;
int n,a[100005],ll,rr;
int b[100005];
string ans1,ans2;
void presort(int x,int *a)
{
if(x>ll)
sort(a+ll,a+x+1);
}
void sufsort(int x,int *a)
{
//if(x<=n)cerr<<x<<endl;
if(n-x+1<rr)
sort(a+n-x+1,a+rr+1);
}
bool check()
{
while(ll<=rr)
{
if(b[ll]==ll)
ll++;
else break;
}
while(ll<=rr)
{
if(b[rr]==rr)
rr--;
else break;
}
return ll>rr;
}
void solpre()
{
int t=(n+1)/2;
for(int i=1;i<=n;i++)
b[i]=a[i];
ll=1;rr=n;
presort(t,b);
sufsort(t-1,b);
if(!check())
{
for(int i=1;i<=t;i++)
if((i+t)&1)ans1+='S';
else ans1+='P';
//cerr<<t<<endl;
int i=t+1;
if((i+t)&1)sufsort(i,b),ans1+='S';
else presort(i,b),ans1+='P';
if(check())return;
i++;
int nl=ll,nr=rr;
// cerr<<i<<" "<<ll<<" "<<rr<<endl;
while(ll<=rr)
{
assert(i>n);
if((i+t)&1)
{
rr-=i+i-1-n;
while(b[nr]>=rr&&ll<=rr)rr--,nr--;
ans1+='S';
}
else
{
ll+=i+i-1-n;
while(b[nl]<=ll&&ll<=rr)ll++,nl++;
ans1+='P';
}
i++;
}
// cerr<<ans1.size();
}
else
{
int now=0;
for(int i=t;i>=1;i--)
{
if((i+t)&1)
{
if(a[n-i+1]!=n-i+1||a[n-i+2]!=n-i+2)
{
now=i;
break;
}
}
else if(a[i]!=i||a[i-1]!=i-1)
{
now=i;
break;
}
}
for(int i=1;i<=now;i++)
if((i+t)&1)ans1+='S';
else ans1+='P';
}
}
void solsuf()
{
int t=(n+1)/2;
for(int i=1;i<=n;i++)
b[i]=a[i];
ll=1;rr=n;
presort(t-1,b);
sufsort(t,b);
if(!check())
{
for(int i=1;i<=t;i++)
if((i+t)&1)ans2+='P';
else ans2+='S';
int i=t+1;
if((i+t)&1)presort(i,b),ans2+='P';
else sufsort(i,b),ans2+='S';
if(check())return;
i++;
int nl=ll,nr=rr;
while(ll<=rr)
{
assert(i>n);
if(!((i+t)&1))
{
rr-=i+i-1-n;
while(b[nr]>=rr&&ll<=rr)rr--,nr--;
ans2+='S';
}
else
{
ll+=i+i-1-n;
while(b[nl]<=ll&&ll<=rr)ll++,nl++;
ans2+='P';
}
i++;
}
// cerr<<ans2.size()<<endl;
}
else
{
int now=0;
for(int i=t;i>=1;i--)
{
if((i+t)&1)
{
if(a[i]!=i||a[i-1]!=i-1)
{
now=i;
break;
}
}
else if(a[n-i+1]!=n-i+1||a[n-i+2]!=n-i+2)
{
now=i;
break;
}
}
for(int i=1;i<=now;i++)
if((i+t)&1)ans2+='P';
else ans2+='S';
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
a[n+1]=n+1;
solpre();
solsuf();
for(int i=1;i<=n;i++)
if(i&1)sufsort(i,a);
else presort(i,a);
// for(int i=1;i<=n;i++)
// cout<<a[i]<<" ";
// cerr<<ans2.size()<<endl;
if(ans1.size()<=ans2.size())
cout<<ans1;
else cout<<ans2;
cout<<'.';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3348kb
input:
3 1 2 3
output:
.
result:
ok OK 0 operations
Test #2:
score: 0
Accepted
time: 2ms
memory: 3380kb
input:
2 2 1
output:
PS.
result:
ok OK 2 operations
Test #3:
score: 0
Accepted
time: 0ms
memory: 3340kb
input:
9 3 2 4 1 5 6 7 9 8
output:
SPSP.
result:
ok OK 4 operations
Test #4:
score: -100
Dangerous Syscalls
input:
10 2 9 5 7 10 6 3 1 8 4