QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#100007 | #6352. SPPPSPSS. | Wolam | WA | 2ms | 3504kb | C++14 | 2.7kb | 2023-04-24 13:14:22 | 2023-04-24 13:14:26 |
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(nl+i<=n&&n-nr+1+i<=n&&ll<=rr)
{
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(nl+i<=n&&n-nr+1+i<=n&&ll<=rr)
{
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++;
}
}
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<<'.';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3400kb
input:
3 1 2 3
output:
.
result:
ok OK 0 operations
Test #2:
score: 0
Accepted
time: 2ms
memory: 3400kb
input:
2 2 1
output:
PS.
result:
ok OK 2 operations
Test #3:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
9 3 2 4 1 5 6 7 9 8
output:
SPSP.
result:
ok OK 4 operations
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 3504kb
input:
10 2 9 5 7 10 6 3 1 8 4
output:
PSPSPSP.
result:
wrong answer the permutation is not sorted