QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634151#9454. String of CCPCucup-team3670#AC ✓177ms3672kbC++171.1kb2024-10-12 16:46:352024-10-12 16:46:35

Judging History

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

  • [2024-10-12 16:46:35]
  • 评测
  • 测评结果:AC
  • 用时:177ms
  • 内存:3672kb
  • [2024-10-12 16:46:35]
  • 提交

answer

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)

using namespace std;

const int M = 7;

int n;
string s;

bool read(){
	if (!(cin >> n))
		return false;
	cin >> s;
	return true;
}

int aut[5][2] = {{1, 0}, {2, 0}, {2, 3}, {4, 0}, {2, 0}};

void solve(){
	vector<vector<vector<int>>> dp(2, vector<vector<int>>(M, vector<int>(5, -1e9)));
	dp[0][0][0] = 0;
	forn(ii, n + 1){
		int i = ii & 1;
		int ni = i ^ 1;
		int c = s[ii] == 'P';
		dp[ni] = vector<vector<int>>(M, vector<int>(5, -1e9));
		forn(j, M) forn(st, 5){
			dp[ni][j][aut[st][c]] = max(dp[ni][j][aut[st][c]], dp[i][j][st] + (aut[st][c] == 4));
			if (j + 1 == M) continue;
			forn(nc, 2)
				dp[i][j + 1][aut[st][nc]] = max(dp[i][j + 1][aut[st][nc]], dp[i][j][st] + (aut[st][nc] == 4) - j);
		}
	}
	int ans = 0;
	forn(j, M) ans = max(ans, *max_element(dp[n & 1][j].begin(), dp[n & 1][j].end()));
	cout << ans << '\n';
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--){
		read();
		solve();
	}
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 177ms
memory: 3672kb

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