QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#631763#9454. String of CCPCucup-team1004#AC ✓47ms5544kbC++171.2kb2024-10-12 10:10:442024-10-12 10:10:45

Judging History

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

  • [2024-10-12 10:10:45]
  • 评测
  • 测评结果:AC
  • 用时:47ms
  • 内存:5544kb
  • [2024-10-12 10:10:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=2e5+10;
int T,n,pre[N],suf[N];
char a[N];
bool chk(char a,char b,char c,char d){
	return a=='C'&&b=='C'&&c=='P'&&d=='C';
}
void get(){
	scanf("%d%s",&n,a+1);
	for(int i=0;i<=n+1;i++)pre[i]=suf[i]=0;
	for(int i=4;i<=n;i++)pre[i]=pre[i-1]+chk(a[i-3],a[i-2],a[i-1],a[i]);
	for(int i=n-3;i>=1;i--)suf[i]=suf[i+1]+chk(a[i],a[i+1],a[i+2],a[i+3]);
	int ans=0;
	for(int i=0;i<=n;i++){
		for(char c:{'C','P'}){
			int x=pre[i]+suf[i+1];
			for(int j=0;j<=3;j++){
				if(i-j+1<1||i+3-j>n)continue;
				static char p[10];
				int cnt=0;
				for(int k=j-1;k>=0;k--)p[cnt++]=a[i-k];
				p[cnt++]=c;
				for(int k=1;k<=3-j;k++)p[cnt++]=a[i+k];
				// assert(cnt==4);
				x+=chk(p[0],p[1],p[2],p[3]);
				ans=max(ans,x);
			}
		}
	}
	printf("%d\n",ans);
}
int main(){
	for(scanf("%d",&T);T--;)get();
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

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

詳細信息

Test #1:

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

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 47ms
memory: 5544kb

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