QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635373 | #9454. String of CCPC | ucup-team5177# | AC ✓ | 25ms | 7276kb | C++14 | 1.6kb | 2024-10-12 19:36:53 | 2024-10-12 19:36:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T, n, t, ans;
ll a[200100];
ll b[200100];
char c[200100];
bool ok(ll x) {
return !b[x] && !b[x + 1] && b[x + 2] == 1 && !b[x + 3];
}
int main() {
scanf("%lld", &T);
while (T--) {
scanf("%lld", &n);
scanf("%s", c + 1);
for (ll i = 1; i <= n; i++) {
if (c[i] == 'C') {
a[i] = 0;
} else {
a[i] = 1;
}
b[i] = a[i];
}
a[n + 2] = a[n + 3] = a[n + 1] = a[0] = -1;
ans = 0;
for (ll i = 1; i + 3 <= n; i++) {
if (ok(i)) {
ans++;
}
}
if (n >= 3) {
if (a[n] && !a[n - 1] && !a[n - 2]) {
ans++;
} else {
for (ll i = 1; i <= n; i++) {
ll x = 0;
ll y = 0;
ll z = 0;
t = 0;
for (ll j = max(1ll, i - 3); j < i; j++) {
b[++t] = a[j];
}
for (ll j = i; j <= min(i + 3, n); j++) {
b[++t] = a[j];
}
for (ll j = 1; j + 3 <= t; j++) {
x += ok(j);
}
t = 0;
for (ll j = max(1ll, i - 3); j < i; j++) {
b[++t] = a[j];
}
b[++t] = 0;
for (ll j = i; j <= min(i + 3, n); j++) {
b[++t] = a[j];
}
for (ll j = 1; j + 3 <= t; j++) {
y += ok(j);
}
t = 0;
for (ll j = max(1ll, i - 3); j < i; j++) {
b[++t] = a[j];
}
b[++t] = 1;
for (ll j = i; j <= min(i + 3, n); j++) {
b[++t] = a[j];
}
for (ll j = 1; j + 3 <= t; j++) {
z += ok(j);
}
if (x < y || x < z) {
ans++;
break;
}
}
}
}
printf("%lld\n", ans);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6008kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 25ms
memory: 7276kb
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