QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#632795#9454. String of CCPCucup-team3661#AC ✓46ms4752kbC++201.2kb2024-10-12 13:58:152024-10-12 13:58:15

Judging History

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

  • [2024-10-12 13:58:15]
  • 评测
  • 测评结果:AC
  • 用时:46ms
  • 内存:4752kb
  • [2024-10-12 13:58:15]
  • 提交

answer

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

int main(){
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		string s;
		cin >> s;
		vector<int> top(n);
		int rec = 0;
		for(int i = 0; i < n-3; ++i){
			if(s.substr(i, 4) == "CCPC"){
				top[i] = 1;
				++rec;
			}
		}
		int ans = rec;
		for(int i = 0; i < n+1; ++i) {
			int tmp = rec;
			for(int j = max(0, i-3); j < i; ++j){
				tmp -= top[j];
			}
			
			for(int j = 3; j >= 0; --j){
				if(i-j < 0) continue;
				if(i+3-j > n) continue;
				if(j == 3){
					if(s.substr(i-j, j) == "CCP"){
						tmp++;
					}
				}
				if(j == 1){
					if(s.substr(i-j, j) == "C" && s.substr(i, 3-j) == "PC"){
						tmp++;
					}
				}
				if(j == 0){
					if(s.substr(i, 3-j) == "CPC"){
						tmp++;
					}
				}
			}
			ans = max(ans, tmp);
			
			tmp = rec;
			for(int j = max(0, i-3); j < i; ++j){
				tmp -= top[j];
			}
			
			for(int j = 3; j >= 0; --j){
				if(i-j < 0) continue;
				if(i+3-j > n) continue;
				if(j == 2){
					if(s.substr(i-j, j) == "CC" && s.substr(i, 3-j) == "C"){
						tmp++;
					}
				}
			}
			ans = max(ans, tmp);
		}
		cout << ans << endl;
	}
	return 0;
}

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

詳細信息

Test #1:

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

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 46ms
memory: 4752kb

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