QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99699#6352. SPPPSPSS.tricyzhkxWA 2ms5712kbC++141.5kb2023-04-23 15:14:412023-04-23 15:14:43

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-23 15:14:43]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 5712kb
  • [2023-04-23 15:14:41]
  • Submitted

answer

# include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int n,p[1000010],a[1000010];
vi solve()
{
	memcpy(a+1,p+1,sizeof(int)*n);
	int lim=((n+1)/2)&1?(n+1)/2:(n+1)/2-1;
	bool ok=1;
	for(int i=1;i<=lim;i++) ok&=(a[i]<=lim);
	for(int i=n;i>lim;i--) ok&=(a[i]>lim);
	if(ok)
	{
		int p=lim,q=lim+1;
		for(;p && a[p]==p;p--);
		for(;q<=n && a[q]==q;q++);
		q=n-q+1;
		if(p && !(p&1)) p++;
		if(q && q&1) q++;
		if(max(p,q)<=lim)
		{
			lim=max(p,q);
			vi ans;
			for(int i=0;i<lim;i++) ans.push_back(i&1);
			return ans;
		}
	}
	sort(a+1,a+lim+1);sort(a+n-lim,a+n+1);
	int l1=1,r1=n-lim-1,l2=n-lim,r2=n;
	for(;l1<=r1 && a[l1]==l1;l1++);
	for(;r2>=l2 && a[r2]==r2;r2--);
	for(int i=lim+2;;i++)
		if(l1>r1)
		{
			vi ans;
			for(int j=0;j<i-1;j++) ans.push_back(j&1);
			return ans;
		}
		else if(i&1)
		{
			int L=a[l2]-1,p=l2+min(i-L-(r1-l1+1),r2-l2+1)-1;
			while(1)
				if(l1<=r1 && a[l1]==L+1) l1++,L++;
				else if(l2<=p && a[l2]==L+1) l2++,L++;
				else break;
		}
		else
		{
			int R=a[r1]+1,p=r1-min(i-(n-R+1)-(r2-l2+1),r1-l1+1)+1;
			while(1)
				if(l2<=r2 && a[r2]==R-1) r2--,R--;
				else if(p<=r1 && a[r1]==R-1) r1--,R--;
				else break;
		}
	return {};
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&p[i]);
	vi v1=solve();
	reverse(p+1,p+n+1);
	for(int i=1;i<=n;i++) p[i]=n-p[i]+1;
	vi v2=solve();
	if(v2.size()<v1.size())
	{
		swap(v1,v2);
		for(int &i:v1) i^=1;
	}
	for(int i:v1) printf("%c","PS"[i]);
	return puts("."),0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5504kb

input:

3
1 2 3

output:

.

result:

ok OK 0 operations

Test #2:

score: 0
Accepted
time: 2ms
memory: 5712kb

input:

2
2 1

output:

PS.

result:

ok OK 2 operations

Test #3:

score: 0
Accepted
time: 2ms
memory: 5656kb

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

input:

10
2 9 5 7 10 6 3 1 8 4

output:

PSPSPSPS.

result:

ok OK 8 operations

Test #5:

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

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

input:

20
17 6 15 14 4 10 18 7 13 8 2 12 1 19 20 3 11 16 5 9

output:

SPSPSPSPSPSPSPSP.

result:

wrong answer Jury (14) found answer better than participant (16)