QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#149716#6352. SPPPSPSS.qzezWA 5ms11224kbC++142.8kb2023-08-25 12:35:452023-08-25 12:35:48

Judging History

你现在查看的是最新测评结果

  • [2023-08-25 12:35:48]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:11224kb
  • [2023-08-25 12:35:45]
  • 提交

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(B[p]<=n-k-1) p++;
		sort(B+p+Ct,B+n+1);
		int flag=0;
		for(i=x+1;i<=n;i++) if(B[i]!=i) flag=1;
		if(flag) x++;
	}else{
		int p=n;while(B[p]>n-k-1) p--;
		sort(B+1,B+p-Ct+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';
	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++;
	}
	// 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-Ct+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+Ct,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';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5812kb

input:

3
1 2 3

output:

.

result:

ok OK 0 operations

Test #2:

score: 0
Accepted
time: 3ms
memory: 10040kb

input:

2
2 1

output:

SP.

result:

ok OK 2 operations

Test #3:

score: 0
Accepted
time: 0ms
memory: 9884kb

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: 10944kb

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: 2ms
memory: 10560kb

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: 2ms
memory: 11224kb

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: -100
Wrong Answer
time: 5ms
memory: 10352kb

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:

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPSPSPSP.

result:

wrong answer the permutation is not sorted