QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635427 | #9454. String of CCPC | ucup-team296# | AC ✓ | 483ms | 4044kb | C++14 | 2.6kb | 2024-10-12 19:47:12 | 2024-10-12 19:47:12 |
Judging History
answer
#include <bits/stdc++.h>
#define long long long int
#define DEBUG
using namespace std;
// @author: pashka
struct test {
vector<int> mc = {1, 2, 2, 4, 2};
vector<int> mp = {0, 0, 3, 0, 0};
int calc(string &s, int k) {
vector<vector<int>> d(k + 1, vector<int>(5, INT_MIN));
d[0][0] = 0;
int n = s.size();
for (int i = 0; i < n; i++) {
vector<vector<int>> dd(k + 1, vector<int>(5, INT_MIN));
for (int j = 0; j <= k; j++) {
for (int x = 0; x < 5; x++) {
// cout << j << " " << x << " " << d[j][x] << "\n";
if (d[j][x] == INT_MIN) continue;
{
int y = 0;
if (s[i] == 'C') {
y = mc[x];
} else if (s[i] == 'P') {
y = mp[x];
}
dd[j][y] = max(dd[j][y], d[j][x] + (y == 4));
}
if (j < k) {
{
int y = mc[x];
d[j + 1][y] = max(d[j + 1][y], d[j][x] + (y == 4));
}
{
int y = mp[x];
d[j + 1][y] = max(d[j + 1][y], d[j][x] + (y == 4));
}
}
}
}
// cout << s[i] << "\n";
d = dd;
}
for (int j = 0; j < k; j++) {
for (int x = 0; x < 5; x++) {
if (d[j][x] == INT_MIN) continue;
{
int y = mc[x];
d[j + 1][y] = max(d[j + 1][y], d[j][x] + (y == 4));
}
{
int y = mp[x];
d[j + 1][y] = max(d[j + 1][y], d[j][x] + (y == 4));
}
}
}
int res = 0;
for (int i = 0; i < 5; i++) {
res = max(res, d[k][i]);
}
// cout << s << " " << k << " " << res << "\n";
return res;
}
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int res = 0;
int ss = 0;
for (int k = 1; k < 5; k++) {
ss += k - 1;
res = max(res, calc(s, k) - ss);
}
cout << res << "\n";
}
};
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
test().solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 483ms
memory: 4044kb
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