QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632276 | #9454. String of CCPC | ucup-team3931# | AC ✓ | 16ms | 3956kb | C++14 | 1.3kb | 2024-10-12 13:08:52 | 2024-10-12 13:08:54 |
Judging History
answer
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 200100;
int n;
char s[maxn];
inline bool check(int i) {
return 1 <= i && i + 3 <= n && s[i] == 'C' && s[i + 1] == 'C' && s[i + 2] == 'P' && s[i + 3] == 'C';
}
void solve() {
scanf("%d%s", &n, s + 1);
int ans = 0;
for (int i = 1; i <= n; ++i) {
ans += check(i);
}
int r = ans;
for (int i = 0; i <= n; ++i) {
int t = r;
t -= check(i - 2);
t -= check(i - 1);
t -= check(i);
t += (1 <= i - 2 && s[i - 2] == 'C' && s[i - 1] == 'C' && s[i] == 'P');
t += (1 <= i && i + 2 <= n && s[i] == 'C' && s[i + 1] == 'P' && s[i + 2] == 'C');
t += (i + 3 <= n && s[i + 1] == 'C' && s[i + 2] == 'P' && s[i + 3] == 'C');
ans = max(ans, t);
t = r;
t -= check(i - 2);
t -= check(i - 1);
t -= check(i);
t += (1 <= i - 1 && i + 1 <= n && s[i - 1] == 'C' && s[i] == 'C' && s[i + 1] == 'C');
ans = max(ans, t);
}
printf("%d\n", ans);
}
int main() {
int T = 1;
scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 16ms
memory: 3956kb
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