QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#665633#9454. String of CCPCucup-team4975#AC ✓14ms4764kbC++231.2kb2024-10-22 14:31:332024-10-22 14:31:45

Judging History

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

  • [2024-10-22 14:31:45]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:4764kb
  • [2024-10-22 14:31:33]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstring>
#include<iomanip>
#include<string>
#include<vector>
using namespace std;

const int N=200010;
int n,a[N];
char s[N];

inline int f(char x,char y,char z,char w){return x=='C'&&y=='C'&&z=='P'&&w=='C';}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int ans=0;
		scanf("%d",&n);
		scanf("%s",s+1);
		for(int i=1;i<=n;i++)
		{
			if(i+4-1<=n)a[i]=f(s[i],s[i+1],s[i+2],s[i+3]);
			else a[i]=0;
			ans+=a[i];
		}
		a[0]=0;
		int oldans=ans;
		for(int i=1;i<=n+1;i++)  //在第i个字母前加
		{
			int pos=oldans;
			if(i-3>=1)pos-=a[i-3],pos+=f(s[i-3],s[i-2],s[i-1],'C');
			if(i-2>=1&&i<=n)pos-=a[i-2],pos+=f(s[i-2],s[i-1],'C',s[i]);
			if(i-1>=1&&i+1<=n)pos-=a[i-1],pos+=f(s[i-1],'C',s[i],s[i+1]);
			if(i+2<=n)pos+=f('C',s[i],s[i+1],s[i+2]);
			ans=max(ans,pos);
			pos=oldans;
			if(i-3>=1)pos-=a[i-3],pos+=f(s[i-3],s[i-2],s[i-1],'P');
			if(i-2>=1&&i<=n)pos-=a[i-2],pos+=f(s[i-2],s[i-1],'P',s[i]);
			if(i-1>=1&&i+1<=n)pos-=a[i-1],pos+=f(s[i-1],'P',s[i],s[i+1]);
			if(i+2<=n)pos+=f('P',s[i],s[i+1],s[i+2]);
			ans=max(ans,pos);
		}
		printf("%d\n",ans);
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 14ms
memory: 4764kb

input:

20003
5
PCCPC
10
CPPPPCPCPC
4
CPPC
11
CCPPCPPPCCP
17
PPPPCPCCCCCPCCCCC
10
PPCCPCPPCP
9
CPCCCCPPC
11
PCPPPPCCPPP
15
CPCPPPPCCPCPCCC
11
PCCPPCCPCPP
9
PCPCCPPCP
10
CCPCPPPCPP
14
CCCCPPPCPCPCPP
2
CC
12
CCPCPPPPPCPP
6
CPPPPP
12
PCCPCCCCCPCC
16
CPCCPCCPPCCCCPPC
7
CPPPCPC
16
PPPPPCCPCPCPCPPC
13
PPPCPCCCCPP...

output:

1
1
0
1
2
1
1
1
2
2
1
1
1
0
1
0
3
2
1
2
1
2
2
0
1
2
3
1
1
3
1
2
2
1
0
0
0
3
1
0
0
1
1
2
0
1
1
0
1
2
0
1
0
1
0
3
1
1
0
2
1
3
2
2
0
2
2
0
0
2
1
1
3
3
1
3
1
2
0
1
1
0
1
2
2
1
1
2
1
3
1
1
3
1
2
2
0
1
0
3
0
1
1
2
2
0
2
1
1
2
2
0
3
1
1
1
1
2
1
2
0
1
1
0
3
0
3
1
1
0
0
1
0
3
0
1
1
1
1
2
2
1
1
0
0
1
2
0
1
2
...

result:

ok 20003 lines

Extra Test:

score: 0
Extra Test Passed