QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686555 | #9454. String of CCPC | ir101# | WA | 137ms | 5500kb | C++20 | 983b | 2024-10-29 14:16:22 | 2024-10-29 14:16:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
s = " " + s + " ";
string ok = "CCPC";
vector pre(n + 3, 0), suf(n + 3, 0);
for (int i = 4; i <= n; i ++) {
pre[i] += pre[i - 1] + (s.substr(i - 3, 4) == ok);
}
for (int i = n - 4; i >= 1; i--) {
suf[i] += suf[i + 1] + (s.substr(i, 4) == ok);
}
int ans = 0;
for (auto c : {'C', 'P'}) {
for (int i = 0; i <= n + 1; i ++) {
int res = 0;
res += pre[i] + suf[i + 1];
for (int j = 1; j <= 4; j++) {
string t = "";
if (j != 1 && i >= (j - 1)) {
t += s.substr(i - (j - 1), (j - 1));
}
t += c;
if (j != 4 && i <= n) {
t += s.substr(i, 4 - j);
}
ans = max(ans, res + (t == ok));
}
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 137ms
memory: 5500kb
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:
2 1 0 1 2 2 1 1 2 2 1 2 1 0 2 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 3 2 0 0 2 1 1 3 3 1 3 1 2 0 1 1 0 1 2 2 1 2 2 1 3 1 1 3 1 3 2 0 1 0 3 0 2 1 2 2 0 2 1 1 2 2 0 3 1 1 1 2 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 2 0 0 1 2 0 1 2 ...
result:
wrong answer 1st lines differ - expected: '1', found: '2'