QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#150265 | #6352. SPPPSPSS. | 275307894a | TL | 5ms | 11416kb | C++14 | 3.0kb | 2023-08-25 16:05:16 | 2023-08-25 16:05:17 |
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+n-mid+2,B+n+1);sort(B+1,B+mid+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 C1=0,C2=0;for(i=1;i<=n-k-1;i++) if(B[i]>n-k-1) C1++,C2++;
int x=k+2;while(1){
int w=x+x-1-n;
if((x-k-1)&1){
if(C1<=w) break;
C1-=w;
}else{
if(C2<=w) break;
C2-=w;
}
x++;
}
for(i=1;i<=n;i++) cerr<<B[i]<<' ';cerr<<'\n';
if((x-k-1)&1){
int p=1;while(B[p]<=n-k-1) p++;
sort(B+p+C2,B+n+1);
int flag=0;
for(i=x+1;i<=n;i++) if(B[i]!=i) flag=1;
cerr<<C2<<'\n';
if(flag) x++;
}else{
int p=n;while(B[p]>n-k-1) p--;
sort(B+1,B+p-C1+1);
int flag=0;
for(i=1;i<=n-x;i++) if(B[i]!=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;}
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';
C1=0;C2=0;for(i=1;i<=k+1;i++) if(B[i]>k+1) C1++,C2++;
x=k+2;while(1){
int w=x+x-1-n;
if((x-k-1)&1){
if(C1<=w) break;
C1-=w;
}else{
if(C2<=w) break;
C2-=w;
}
x++;
}
// for(i=1;i<=n;i++) cerr<<B[i]<<' ';
if((x-k-1)&1){
int p=n;while(B[p]>k+1) p--;
sort(B+1,B+p-C1+1);
int flag=0;
for(i=1;i<=n-x;i++) if(B[i]!=i) flag=1;
if(flag) x++;
}else{
int p=1;while(B[p]<=k+1) p++;
sort(B+p+C2,B+n+1);
int flag=0;
for(i=x+1;i<=n;i++) if(B[i]!=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';
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5828kb
input:
3 1 2 3
output:
.
result:
ok OK 0 operations
Test #2:
score: 0
Accepted
time: 3ms
memory: 9924kb
input:
2 2 1
output:
SP.
result:
ok OK 2 operations
Test #3:
score: 0
Accepted
time: 4ms
memory: 9924kb
input:
9 3 2 4 1 5 6 7 9 8
output:
SPSP.
result:
ok OK 4 operations
Test #4:
score: 0
Accepted
time: 5ms
memory: 11112kb
input:
10 2 9 5 7 10 6 3 1 8 4
output:
PPPPPSPS.
result:
ok OK 8 operations
Test #5:
score: 0
Accepted
time: 5ms
memory: 10608kb
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: 10064kb
input:
20 17 6 15 14 4 10 18 7 13 8 2 12 1 19 20 3 11 16 5 9
output:
PPPPPPPPPPSPSP.
result:
ok OK 14 operations
Test #7:
score: 0
Accepted
time: 0ms
memory: 10508kb
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:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPSPSPSPS.
result:
ok OK 57 operations
Test #8:
score: 0
Accepted
time: 1ms
memory: 11416kb
input:
1000 668 554 210 852 617 846 561 95 341 893 276 224 287 1000 356 362 897 205 369 654 181 590 339 377 346 557 382 593 55 62 126 899 49 509 977 585 614 232 865 800 790 292 219 957 379 914 946 246 294 403 940 517 768 623 376 624 331 353 887 626 424 449 115 628 569 809 956 942 300 894 61 936 678 779 549...
output:
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
result:
ok OK 523 operations
Test #9:
score: -100
Time Limit Exceeded
input:
100000 30619 15529 4854 9258 46894 29948 59533 56945 19473 7608 42291 95532 80537 83105 70434 68130 89221 96367 26768 43837 54765 52814 88446 14950 63224 63479 11957 41446 38702 8466 85556 57724 50097 29014 17961 65178 88627 96815 80115 79096 19625 2979 51033 68224 48649 96250 3406 96433 22584 79610...