QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#640593 | #9454. String of CCPC | ucup-team093# | AC ✓ | 143ms | 27384kb | C++20 | 1.4kb | 2024-10-14 14:33:50 | 2024-10-14 14:33:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, M = 6;
int dp[N][M][5];
int nxt[5][2];
int solve() {
int n;
string s;
cin >> n >> s;
for(int j = 0; j < M; j ++)
for(int k = 0; k < 5; k ++)
dp[0][j][k] = -1e9;
dp[0][0][0] = 0;
for(int i = 0; i <= n; i ++) {
for(int j = 0; j + 1 < M; j ++)
for(int k = 0; k < 5; k ++)
for(int x : {0, 1})
dp[i][j + 1][nxt[k][x]] = max(dp[i][j + 1][nxt[k][x]], dp[i][j][k] - j + (nxt[k][x] == 4));
if(i == n) continue;
for(int j = 0; j < M; j ++)
for(int k = 0; k < 5; k ++)
dp[i + 1][j][k] = -1e9;
int x = s[i] == 'P';
for(int j = 0; j < M; j ++)
for(int k = 0; k < 5; k ++)
dp[i + 1][j][nxt[k][x]] = max(dp[i + 1][j][nxt[k][x]], dp[i][j][k] + (nxt[k][x] == 4));
}
int ans = 0;
for(int j = 0; j < M; j ++)
for(int k = 0; k < 5; k ++)
ans = max(ans, dp[n][j][k]);
return ans;
}
int main() {
nxt[0][0] = 1;
nxt[1][0] = 2;
nxt[2][0] = 2;
nxt[2][1] = 3;
nxt[3][0] = 4;
nxt[4][0] = 2;
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T --) {
cout << solve() << "\n";
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3764kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 143ms
memory: 27384kb
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