QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#631589#9454. String of CCPCucup-team2279#AC ✓147ms3980kbC++20535b2024-10-12 09:01:072024-10-12 09:01:07

Judging History

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

  • [2024-10-12 09:01:07]
  • 评测
  • 测评结果:AC
  • 用时:147ms
  • 内存:3980kb
  • [2024-10-12 09:01:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
void solve(){
	int n,sum=0,ans=0;
	string s;
	cin>>n>>s;
	for(int i=0;i+3<n;i++) if(s.substr(i,4)=="CCPC") sum++;
	for(int i=0;i<=n;i++) for(int o:{0,1}){
		int v=sum;
		for(int j=max(i-3,0);j<i&&j+3<n;j++) v-=s.substr(j,4)=="CCPC";
		for(int j=max(i-3,0);j<=i&&j+3<=n;j++) v+=s.substr(j,i-j)+(o?"C":"P")+s.substr(i,3-i+j)=="CCPC";
		ans=max(ans,v);
	}
	cout<<ans<<"\n";
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 147ms
memory: 3980kb

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