QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632662 | #9454. String of CCPC | ucup-team5062# | AC ✓ | 526ms | 49972kb | C++17 | 1006b | 2024-10-12 13:44:55 | 2024-10-12 13:44:55 |
Judging History
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