QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#647470 | #9454. String of CCPC | ucup-team4479# | AC ✓ | 27ms | 16436kb | C++23 | 1.7kb | 2024-10-17 14:21:16 | 2024-10-17 14:21:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int dp[N][2][8];
void solve() {
int n;
string s;
cin >> n >> s;
int goal = 13;
for (int i = 0; i <= n; ++i)
for (int j = 0; j < 8; ++j)
dp[i][0][j] = dp[i][1][j] = -1;
dp[0][1][1] = dp[0][1][0] = 0;
dp[0][0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int sta = 0; sta < 8; ++sta) {
if (dp[i][0][sta] != -1) {
// printf("dp[%d][0][%d] = %d\n", i, sta, dp[i][0][sta]);
int ch = s[i] == 'C', val = ((sta << 1) ^ ch) == goal;
int nxt = ((sta & 3) << 1) ^ ch;
dp[i + 1][0][nxt] = max(dp[i + 1][0][nxt], dp[i][0][sta] + val);
int nxc = ((nxt & 3) << 1) ^ 1, valc = ((nxt << 1) ^ 1) == goal;
dp[i + 1][1][nxc] = max(dp[i + 1][1][nxc], dp[i][0][sta] + val + valc);
int nxp = ((nxt & 3) << 1), valp = (nxt << 1) == goal;
dp[i + 1][1][nxp] = max(dp[i + 1][1][nxp], dp[i][0][sta] + val + valp);
}
if (dp[i][1][sta] != -1) {
// printf("dp[%d][1][%d] = %d\n", i, sta, dp[i][1][sta]);
int ch = s[i] == 'C', val = ((sta << 1) ^ ch) == goal;
int nxt = ((sta & 3) << 1) ^ ch;
dp[i + 1][1][nxt] = max(dp[i + 1][1][nxt], dp[i][1][sta] + val);
}
}
}
int ans = 0;
for (int i = 0; i < 8; ++i)
ans = max(ans, max(dp[n][0][i], dp[n][1][i]));
cout << ans << endl;
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cout.tie(0);
int T;
cin >> T;
while (T--) solve();
return 0;
}
/*
3
3
CPC
6
CCPCPC
3
CCP
*/
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 27ms
memory: 16436kb
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