QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#631666#9454. String of CCPCucup-team3555#AC ✓26ms3836kbC++17960b2024-10-12 09:31:042024-10-12 09:31:05

Judging History

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

  • [2024-10-12 09:31:05]
  • 评测
  • 测评结果:AC
  • 用时:26ms
  • 内存:3836kb
  • [2024-10-12 09:31:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=1e6+3;
int n;
char ch[N];
bool Ok(int x)
{
	if(x<=0||x+3>n)return 0;
	return ch[x]=='C'&&ch[x+1]=='C'&&ch[x+2]=='P'&&ch[x+3]=='C'; 
}
bool Chk4(int x)
{
	if(x<=0&&x+2>n)return 0;
	return ch[x]=='C'&&ch[x+1]=='C'&&ch[x+2]=='P';
}
bool Chk3(int x)
{
	if(x<=0||x+2>n)return 0;
	return ch[x]=='C'&&ch[x+1]=='C'&&ch[x+2]=='C';
}
bool Chk2(int x)
{
	if(x<=0||x+2>n)return 0;
	return ch[x]=='C'&&ch[x+1]=='P'&&ch[x+2]=='C';
}
bool Chk1(int x)
{
	if(x<=0||x+2>n)return 0;
	return ch[x]=='C'&&ch[x+1]=='P'&&ch[x+2]=='C'; 
}
void Solve()
{
	cin>>n>>(ch+1);ch[0]=ch[n+1]='#';
	if(n<=2){cout<<0<<endl;return;}
	int sum=0,fl=0;
	for(int i=1;i<=n;i++)sum+=Ok(i);
	for(int i=0;i<=n;i++)if(!Ok(i-2)&&!Ok(i-1)&&!Ok(i))
		if(Chk4(i-2)||Chk3(i-1)||Chk2(i)||Chk1(i+1)){fl=1;break;}
	cout<<sum+fl<<endl;
}
int main()
{
	int T;cin>>T;
	while(T--)Solve();
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 26ms
memory: 3836kb

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