QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#367959#6505. CCPC StringNaXiiWA 35ms3700kbC++141.1kb2024-03-26 17:43:152024-03-26 17:43:15

Judging History

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

  • [2024-03-26 17:43:15]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:3700kb
  • [2024-03-26 17:43:15]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std ;
const int N = 1e6 + 10 ;

int T , n ;
int sum[N] , ans ;
string s ;

bool check(int mid , int x)
{
	x ++ ;
	if(x + mid > n) return false ;
	if(s[x - 1] == '?')
	{
		if(sum[x] - 1 - sum[x - 2*mid - 1] < 2*mid) return false ;
		if(sum[x + mid] - sum[x] < mid) return false ;
	}else
	{
		if(sum[x] - sum[x - 2*mid - 1] < 2*mid) return false ;
		if(sum[x + mid] - sum[x] < mid) return false ;
	}
	
	return true ;
}

void solve()
{
	ans = 0 ;
	cin >> s ;
	
	n = s.length() ;
	for(int i = 1 ; i <= n ; i ++)
	{
		if(s[i - 1] != 'p') sum[i] = sum[i - 1] + 1 ;
		else sum[i] = sum[i - 1] ;
	}
	
	for(int i = 0 ; i < n ; i ++)
	{
		if(s[i] == 'c') continue ;
		else 
		{
			int l = 0 , r = sum[i + 1] ;
			r >> 1 ;
			while(r > l)
			{
				int mid = (l + r + 1) >> 1 ;
				if(check(mid , i)) l = mid ;
				else r = mid - 1 ;
			}
			//cout << l << i << ' ' ;
			ans += l ;
		}
	}
	
	cout << ans << '\n' ;
}

int main()
{
	ios::sync_with_stdio(false) ;
	cin.tie(0) ;
	cout.tie(0) ; 
	
	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: 3644kb

input:

5
?cpc
ccp??
???c???
?c???cp??
?c?????cccp????

output:

1
1
4
5
14

result:

ok 5 number(s): "1 1 4 5 14"

Test #2:

score: 0
Accepted
time: 19ms
memory: 3644kb

input:

100000
c?cp?pp?c?
ppp????pcc
c?ppppcc?p
?p?cc?ccpc
pc?ppc?cp?
?pp?p?c?cp
p???pcccpp
cpcccpcc??
????c?cc?p
pcp?pppcp?
cc?pccc?pp
cpc??c?p?c
??c??cpppc
cpcp?pc??c
pcc??ppccp
?p?p?cpcpp
c?ccpcpp??
ppc?cccccp
cp?pcccppp
cccc???ccc
c?pcc?pp?p
pcc?p??cp?
?cc??ppp?p
?ppp??p?pp
??pccc??p?
???cccpp??
c???c?p...

output:

1
3
0
2
1
1
1
2
4
0
1
3
2
1
1
1
1
0
0
7
1
2
1
1
3
1
3
1
2
2
2
3
0
2
1
8
0
3
2
0
1
1
1
1
1
0
3
0
3
3
2
1
4
0
1
1
1
1
2
1
6
4
3
1
4
1
2
1
1
0
1
2
5
1
1
3
2
1
1
2
1
5
0
0
2
1
3
1
2
0
4
0
0
1
5
2
0
1
0
1
0
0
1
0
1
2
0
0
0
0
3
0
0
2
1
3
2
4
2
0
1
3
1
3
1
3
2
1
2
0
1
2
0
0
5
0
4
4
0
0
2
3
0
1
1
0
1
0
1
1
...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 16ms
memory: 3640kb

input:

100000
???pp??c??
p??pcccp??
p?pp??cc??
p????pp???
?c?ppp????
?pp???pcp?
???????c??
c?p?p?c?pp
??c?cpp?pc
pc?ccp??p?
p????p?pc?
pppcc??cp?
c??cpp????
?pc?p?p???
??cp?p????
?ppppccp??
????c???cc
c?c?cp???p
??c??c?p?c
p?p?pp??p?
?pc??pp???
pcc??pcpcc
??p?cc?p??
?c???c????
p?c?cp??p?
??c???pc?c
?p?c?c?...

output:

1
2
1
1
1
1
10
1
1
3
2
3
2
1
2
1
9
3
5
1
0
2
3
10
4
5
3
3
2
0
8
1
1
1
4
3
3
7
3
7
2
3
4
8
1
3
7
2
10
0
6
1
7
0
1
3
2
6
10
2
5
4
6
4
1
3
5
3
1
2
9
0
2
1
2
7
4
2
10
4
9
5
6
3
3
4
3
0
4
6
4
5
1
4
3
5
2
3
7
2
9
3
3
3
2
4
5
3
3
5
4
6
1
1
12
9
3
3
2
9
5
5
5
9
3
3
5
3
2
4
4
0
3
4
2
5
0
1
4
3
4
5
3
2
6
7
5
...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 19ms
memory: 3556kb

input:

10000
ccp?pc?cp?cp??ppcc??ccp?cppcpc???cccccp??cp?pcppcp?c??pcppcpc??pc?pcppppccpp?pppcp?pcp?p?c?c????cccc
p???ccppccc?p?????ccp?c?p?ppcccpcp??c?cppccc?cp???pc?p?pc?cppp?pp?ppc?c???cc?ccp?p???pp?pccp?cc??cc?
ccccp?cp?pp?pcc??pc?pc??c??ppp????pccpp?cpccpc?p?pcpppc?pppp?c?ccc?cpc?cpcp????pp?ppccp?pccp...

output:

28
30
26
23
23
26
23
25
26
20
32
28
34
19
29
13
12
30
19
38
32
22
31
25
29
32
34
29
28
17
27
61
16
16
29
12
42
36
15
13
18
27
15
20
28
23
38
38
34
35
30
25
27
43
31
26
20
23
45
41
87
25
27
25
32
21
35
19
35
21
17
20
26
45
32
21
23
23
35
24
12
24
29
33
35
19
21
20
30
16
26
13
27
24
28
27
37
19
24
25
...

result:

ok 10000 numbers

Test #5:

score: 0
Accepted
time: 21ms
memory: 3656kb

input:

1000
??pp??pcpp?ccp??pp?ppcpc?c???pcpcp?cccpppc?c?ppc?p?pcc??cccc??cppc?pc???ppp?p?p?ppccp?cpcc?cpc?pcp?c??c?pc??cp?cpcp?pc?p?cpccc??cccc??c??cpcccc??ccppc??pc?ppp??ppccp??c?ppp?ppccpcpc?cccp?pccpc?pc?ccppc?pcppccc??c??????cpp?pp?c?pp?ccccp?pc??cc?cpcpcpp???ccpcp?cccp?pp?ccc?ppccccp??????c?cc??c?ccp...

output:

290
280
266
279
289
304
385
292
242
316
245
245
247
253
254
390
297
279
277
267
254
280
267
347
237
264
333
262
285
285
267
236
249
294
327
305
266
274
258
259
260
313
278
271
272
261
296
219
254
282
296
257
231
250
251
293
315
261
289
302
286
231
277
302
263
262
260
290
251
294
247
243
320
344
318
...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 35ms
memory: 3700kb

input:

1000
?????????????????????????????????p??????????????????????????????????????????p??????????????????????????????????????????????????????????????p????????????cp?????????????????????????????????????????????????????????????????????????????c???????????????????????????????????????????????????????????????...

output:

24795
38683
43374
40572
19397
29397
33629
25374
34988
27882
30805
17920
19482
28640
36088
23120
22234
29923
40073
32290
23138
19252
19047
31091
20720
13892
35194
28153
16235
95681
17487
30610
34861
31112
22008
14669
17720
21254
20388
63985
26402
25313
21735
36330
43267
39793
32223
41635
26991
23431
...

result:

ok 1000 numbers

Test #7:

score: -100
Wrong Answer
time: 34ms
memory: 3656kb

input:

1000
??p???????????????????????????????????????????????p????????????????????????????????????????????????????c??????c??????????c????????????????????????????????????????????????c??????c???c?????????????????????????????????????????????c????c??????c????????????????c???????c???c??????????????????????????...

output:

38431
50325
40041
38642
54638
51644
65069
80176
50145
77187
99305
29692
55661
49128
67468
48058
47507
53684
58318
54057
33448
78524
37534
43797
40568
34123
31270
60175
75099
55714
28945
36047
42956
31432
51861
23652
79716
112982
71348
55645
32387
60564
37551
34998
34530
30474
41652
62836
47828
25220...

result:

wrong answer 7th numbers differ - expected: '65061', found: '65069'