QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639130 | #9454. String of CCPC | supepapupu | AC ✓ | 44ms | 4292kb | C++20 | 1.3kb | 2024-10-13 18:01:26 | 2024-10-13 18:01:28 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
#define el '\n'
#define debug(x) cout << #x << ": " << x << el
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;
void solve() {
int n; cin >> n;
string str; cin >> str;
int ans = 0;
for (int i = 0; i + 3 < n; ++i) {
ans += str.substr(i, 4) == "CCPC";
}
int mx = 0;
for (int i = 0; i < n; ++i) {
int del = (i > 1 && i + 1 < n ? str.substr(i - 2, 4) == "CCPC" : 0)
+ (i && i + 2 < n ? str.substr(i - 1, 4) == "CCPC" : 0)
+ (i + 3 < n ? str.substr(i, 4) == "CCPC" : 0);
int add1 = (i > 1 ? str.substr(i - 2, 3) == "CCP" : 0)
+ (i + 2 < n ? str.substr(i, 3) == "CPC" : 0)
+ (i + 3 < n ? str.substr(i + 1, 3) == "CPC" : 0);
int add2 = (i && i + 1 < n ? str.substr(i - 1, 2) == "CC" && str[i + 1] == 'C' : 0);
mx = max(mx, max(add1, add2) - del);
// cout << i << ' ' << del << ' ' << add1 << el;
}
cout << ans + mx << el;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int tcase = 1;
cin >> tcase;
while (tcase--) solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 44ms
memory: 4292kb
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