QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149685 | #6352. SPPPSPSS. | qzez# | WA | 4ms | 10940kb | C++14 | 2.7kb | 2023-08-25 10:17:45 | 2023-08-25 10:17:47 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e6+5,M=N*5+5,K=14348907+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,A[N],B[N];char ans[N],ts[N];int len;
int CK1(int mid){
Mc(B,A);
sort(B+1,B+mid+1);sort(B+n-mid+2,B+n+1);
for(int i=1;i<=n;i++) if(B[i]^i) return 0;
return 1;
}
int CK2(int mid){
Mc(B,A);
sort(B+1,B+mid);sort(B+n-mid+1,B+n+1);
for(int i=1;i<=n;i++) if(B[i]^i) return 0;
return 1;
}
void DoP(int x){sort(B+1,B+x+1);}
void DoS(int x){sort(B+n-x+1,B+n+1);}
int k;
void Solve(){
int i,j;scanf("%d",&n);len=n+1;
for(i=1;i<=n;i++) scanf("%d",&A[i]);
int flag=0;for(i=1;i<=n;i++) flag|=A[i]^i;
if(!flag){puts(".");return;}
int l=-1,r=n+1,mid;while(l+1<r) mid=l+r>>1,(CK1(mid)?r:l)=mid;
len=r;for(i=1;i<=r;i++) ans[i]=((r-i)&1?'S':'P');
l=max(l-1,-1);r=min(r+1,n+1);
while(l+1<r) mid=l+r>>1,(CK2(mid)?r:l)=mid;
if(len>r){
len=r;for(i=1;i<=r;i++) ans[i]=((r-i)&1?'P':'S');
}
if(len<=n/2+1){
ans[len+1]='.';printf("%s\n",ans+1);
return;
}
k=n/2;
for(i=1;i<k;i++) ts[i]='P';
Mc(B,A);
DoP(k);DoS(k+1);
ts[k]='P';ts[k+1]='S';
int Ct=0;for(i=1;i<=n-k-1;i++) if(B[i]>n-k-1) Ct++;
int x=k+2;while(1){
int w=x+x-1-n;
if(Ct<w) break;
else Ct-=w;
x++;
}
if((x-k-1)&1){
int p=1;while(A[p]<=n-k-1) p++;
int flag=0;
for(i=1;i<=Ct;i++) if(A[p+i-1]!=n-k-1+i) flag=1;
cerr<<flag<<'\n';
if(flag) x++;
}else{
int p=n;while(A[p]>n-k-1) p--;
int flag=0;
for(i=1;i<=Ct;i++) if(A[p-i+1]!=n-k-1-i+1) flag=1;
if(flag) x++;
}
for(i=k+2;i<=x;i++) ts[i]=((i-k-1)&1?'P':'S');
if(x<len) {Mc(ans,ts);len=x;}
Me(ts,0);for(i=1;i<k;i++) ts[i]='P';
Mc(B,A);
DoS(k);DoP(k+1);
ts[k]='S';ts[k+1]='P';
Ct=0;for(i=1;i<=k+1;i++) if(B[i]>k+1) Ct++;
x=k+2;while(1){
int w=x+x-1-n;
if(Ct<w) break;
else Ct-=w;
x++;
}
if((x-k-1)&1){
int p=n;while(A[p]>k+1) p--;
int flag=0;
for(i=1;i<=Ct;i++) if(A[p-i+1]!=k+1-i+1) flag=1;
if(!flag) x++;
}else{
int p=1;while(A[p]<=k+1) p++;
int flag=0;
for(i=1;i<=Ct;i++) if(A[p+i-1]!=k+1+i) flag=1;
if(!flag) x++;
}
for(i=k+2;i<=x;i++) ts[i]=((i-k-1)&1?'P':'S');
if(x<len) {Mc(ans,ts);len=x;}
ans[len+1]='.';printf("%s\n",ans+1);
}
int main(){
int t;
// scanf("%d",&t);
t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5828kb
input:
3 1 2 3
output:
.
result:
ok OK 0 operations
Test #2:
score: 0
Accepted
time: 1ms
memory: 9964kb
input:
2 2 1
output:
SP.
result:
ok OK 2 operations
Test #3:
score: 0
Accepted
time: 3ms
memory: 9996kb
input:
9 3 2 4 1 5 6 7 9 8
output:
SPSP.
result:
ok OK 4 operations
Test #4:
score: 0
Accepted
time: 4ms
memory: 10116kb
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: 1ms
memory: 10940kb
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: -100
Wrong Answer
time: 1ms
memory: 9808kb
input:
20 17 6 15 14 4 10 18 7 13 8 2 12 1 19 20 3 11 16 5 9
output:
PPPPPPPPPSPPS.
result:
wrong answer the permutation is not sorted