QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#635373#9454. String of CCPCucup-team5177#AC ✓25ms7276kbC++141.6kb2024-10-12 19:36:532024-10-12 19:36:54

Judging History

你现在查看的是最新测评结果

  • [2024-10-12 19:36:54]
  • 评测
  • 测评结果:AC
  • 用时:25ms
  • 内存:7276kb
  • [2024-10-12 19:36:53]
  • 提交

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