QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#632496#9454. String of CCPCucup-team918#AC ✓16ms3872kbC++171.6kb2024-10-12 13:28:432024-10-12 13:28:43

Judging History

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

  • [2024-10-12 13:28:43]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:3872kb
  • [2024-10-12 13:28:43]
  • 提交

answer

#include <bits/stdc++.h>
#define cerr cout << "in " << __LINE__ << "\t: "
using namespace std;
int n, tmp;
string s;
void Solve(int test) {
	cin >> n >> s, s = " " + s;
	int res = 0;
	for (int i = 1; i + 3 <= n; i++)
		if (s[i] == 'C' && s[i + 1] == 'C' && s[i + 2] == 'P' && s[i + 3] == 'C')
			res++;
	int ans = res, tmp;
	for (int i = 0; i <= n; i++) {
		// C
		tmp = res;
		if (i >= 3 && i < n)
			tmp -= s[i - 2] == 'C' && s[i - 1] == 'C' && s[i] == 'P' && s[i + 1] == 'C';
		if (i >= 2 && i < n - 1)
			tmp -= s[i - 1] == 'C' && s[i] == 'C' && s[i + 1] == 'P' && s[i + 2] == 'C';
		if (i >= 1 && i < n - 2)
			tmp -= s[i] == 'C' && s[i + 1] == 'C' && s[i + 2] == 'P' && s[i + 3] == 'C';
		if (i >= 3)
			tmp += s[i - 2] == 'C' && s[i - 1] == 'C' && s[i] == 'P';
		if (i >= 1 && i < n - 1)
			tmp += s[i] == 'C' && s[i + 1] == 'P' && s[i + 2] == 'C';
		if (i < n - 2)
			tmp += s[i + 1] == 'C' && s[i + 2] == 'P' && s[i + 3] == 'C';
		ans = max(ans, tmp);
		// P
		tmp = res;
		if (i >= 3 && i < n)
			tmp -= s[i - 2] == 'C' && s[i - 1] == 'C' && s[i] == 'P' && s[i + 1] == 'C';
		if (i >= 2 && i < n - 1)
			tmp -= s[i - 1] == 'C' && s[i] == 'C' && s[i + 1] == 'P' && s[i + 2] == 'C';
		if (i >= 1 && i < n - 2)
			tmp -= s[i] == 'C' && s[i + 1] == 'C' && s[i + 2] == 'P' && s[i + 3] == 'C';
		if (i >= 2 && i < n)
			tmp += s[i - 1] == 'C' && s[i] == 'C' && s[i + 1] == 'C';
		ans = max(ans, tmp);
	}
	cout << ans << "\n";
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T;
	cin >> T;
	for (int i = 1; i <= T; i++) Solve(i);
	return 0;
}

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

詳細信息

Test #1:

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

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 16ms
memory: 3872kb

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