QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632662#9454. String of CCPCucup-team5062#AC ✓526ms49972kbC++171006b2024-10-12 13:44:552024-10-12 13:44:55

Judging History

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

  • [2024-10-12 13:44:55]
  • 评测
  • 测评结果:AC
  • 用时:526ms
  • 内存:49972kb
  • [2024-10-12 13:44:55]
  • 提交

answer

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

const int INF = 1012345678;

int main() {
	int T;
	cin >> T;
	vector<vector<int> > tbl = {
		{1, 0},
		{2, 0},
		{2, 3},
		{1, 0}
	};
	for (int id = 1; id <= T; id++) {
		int N; string S;
		cin >> N >> S;
		vector<int> dp((N + 1) * 44, -1);
		auto dfs = [&](auto& self, int pos, int d, int s) -> int {
			if (d > 10) {
				return -INF;
			}
			int h = pos * 44 + d * 4 + s;
			if (dp[h] != -1) {
				return dp[h];
			}
			int ans = -(d * (d - 1) / 2);
			for (int i = 0; i < 2; i++) {
				char c = (i == 0 ? 'C' : 'P');
				int f = 0;
				if (pos != N && S[pos] == c) {
					f = 1;
				}
				int res = self(self, pos + (f == 1 ? 1 : 0), d + (f == 1 ? 0 : 1), tbl[s][i]);
				if (s == 3 && i == 0) {
					res++;
				}
				ans = max(ans, res);
			}
			dp[h] = ans;
			return ans;
		};
		int result = dfs(dfs, 0, 0, 0);
		cout << result << endl;
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3484kb

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 526ms
memory: 49972kb

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