QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686576#9454. String of CCPCucup-team059#AC ✓70ms4244kbC++201.2kb2024-10-29 14:25:462024-10-29 14:25:47

Judging History

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

  • [2024-10-29 14:25:47]
  • 评测
  • 测评结果:AC
  • 用时:70ms
  • 内存:4244kb
  • [2024-10-29 14:25:46]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long

void solve(){
	int n;
	std::string s;

	std::cin >> n >> s;
	int sum = 0;
	for (int i = 0;i + 3 < n;i++){
		if (s.substr(i, 4) == "CCPC"){
			sum++;
		}
	}
	int ans = sum;
	for (int i = 0;i <= n;i++){
		int l = std::max(0, i - 4), r = std::min(n - 1, i + 4);
		int tmp = sum;
		for (int j = l;j + 3 <= r;j++){
			if (s[j] == 'C' && s[j + 1] == 'C' && s[j + 2] == 'P' && s[j + 3] == 'C'){
				tmp--;
			}
		}
		std::string pre;
		for (int j = l;j < i;j++){
			pre.push_back(s[j]);
		}
		std::string nxt;
		for (int j = i;j <= r;j++){
			nxt.push_back(s[j]);
		}
		std::string t1 = pre + "C" + nxt;
		std::string t2 = pre + "P" + nxt;
		int cur1 = tmp,cur2 = tmp;
		for (int j = 0;j + 3 < t1.size();j++){
			if ((t1[j] == 'C' && t1[j + 1] == 'C' && t1[j + 2] == 'P' && t1[j + 3] == 'C')){
				cur1++;
			}
		}
		for (int j = 0;j + 3 < t1.size();j++){
			if ((t2[j] == 'C' && t2[j + 1] == 'C' && t2[j + 2] == 'P' && t2[j + 3] == 'C')){
				cur2++;
			}
		}
		ans = std::max({ans, cur1, cur2});
	}
	std::cout << ans << '\n';
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t;
	std::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: 3608kb

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 70ms
memory: 4244kb

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