QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#85171#3293. 优秀的拆分zombie462100 ✓87ms4620kbC++231.3kb2023-03-07 02:16:302023-03-07 02:16:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-07 02:16:58]
  • 评测
  • 测评结果:100
  • 用时:87ms
  • 内存:4620kb
  • [2023-03-07 02:16:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 33333
#define mod 30000010
char s[N];
LL hs[N],bs[N],u[N],v[N],ans;
LL gethash(int l,int r){
	return ((hs[l]-hs[r]*bs[r-l])%mod+mod)%mod;
}
signed main(){
	int T;scanf("%d",&T);
	bs[0]=1;
	for (int i=1;i<N;++i) bs[i]=bs[i-1]*27%mod;
	while (T --> 0){
		scanf("%s",s+1);
		int n=strlen(s+1);		
		memset(u,0,sizeof(u));
		memset(v,0,sizeof(v));
		hs[n+1]=0;
		for (int i=n;i;--i){
			hs[i]=(hs[i+1]*27+s[i]-'a'+1)%mod;
		}
		for (int j=1;j*2<=n;++j){
			for (int i=j*2;i<=n;i+=j){
				if (s[i]!=s[i-j]) continue;
				int l=1,r=j,lst=i-j,pos=0;
				while (l<=r){
					int mid=(l+r)/2;
					if (gethash(lst-mid+1,lst+1)==gethash(i-mid+1,i+1)){
						pos=mid;l=mid+1;
					}else r=mid-1;
				}
				int t=i-pos+1;
				l=1,r=j,pos=0;
				while (l<=r){
					int mid=(l+r)/2;
					if (gethash(lst,lst+mid)==gethash(i,i+mid)){
						pos=mid;l=mid+1;
					}else r=mid-1;
				}
				int w=i+pos-1;
				t=max(t+j-1,i);
				w=min(w,i+j-1);
				if (t<=w){
					u[t-2*j+1]++;u[w-2*j+2]--;
					v[t]++;v[w+1]--;
				}
			}
		}
		ans=0;
		for (int i=1;i<=n;++i){
			u[i]+=u[i-1];
			v[i]+=v[i-1];
		} 
		for (int i=1;i<n;++i) ans+=v[i]*u[i+1];
		printf("%lld\n",ans);
	}
	return 0;
}

详细

Test #1:

score: 5
Accepted
time: 4ms
memory: 4424kb

input:

10
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

462056
140600
875978
575960
811035
299536
173880
414090
227128
924490

result:

ok 10 numbers

Test #2:

score: 5
Accepted
time: 3ms
memory: 4352kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

369564
513590
285760
308945
408312
190568
180441
328350
437635
1091574

result:

ok 10 numbers

Test #3:

score: 5
Accepted
time: 4ms
memory: 4472kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

92601930
126763350
233408728
111659395
147774025
41791750
62056280
198982282
172593608
298613460

result:

ok 10 numbers

Test #4:

score: 5
Accepted
time: 5ms
memory: 4620kb

input:

10
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...

output:

241383298
63369600
53220335
75846485
53073182
47276061
287600152
128609208
205431400
71461299

result:

ok 10 numbers

Test #5:

score: 5
Accepted
time: 3ms
memory: 4456kb

input:

10
nnnnnnnnnn
hzhzhzhzhz
zezezezeze
ndndndndnd
zvzvzvzvzv
bbbbbbbbbb
sgsgsgsgsg
fgfgfgfgfg
hxhxhxhxhx
fafafafafa

output:

30
3
3
3
3
30
3
3
3
3

result:

ok 10 numbers

Test #6:

score: 5
Accepted
time: 3ms
memory: 4360kb

input:

10
xxxxxxxxxx
wtwtwtwtwt
sososososo
xgxgxgxgxg
lblblblblb
rororororo
qfqfqfqfqf
qjqjqjqjqj
upupupupup
nynynynyny

output:

30
3
3
3
3
3
3
3
3
3

result:

ok 10 numbers

Test #7:

score: 5
Accepted
time: 3ms
memory: 4356kb

input:

10
jjjjjjjjjjjjjjjjjjjj
tgtgtgtgtg
mcomcomcomco
wthwthwthwth
aaitaaitaaitaait
pvaompvaompvaompvaom
ahahahahah
jwxmjwxmjwxmjwxm
pdfpdfpdfpdf
oiyfoiyfoiyfoiyf

output:

285
3
1
1
5
1
3
1
1
1

result:

ok 10 numbers

Test #8:

score: 5
Accepted
time: 3ms
memory: 4600kb

input:

10
iiiiiiiiiiiiiiiii
scscscscscscsc
bsobsobsobsobso
rppyrppyrppyrppy
xhnxhnxhnxhn
jfbjfbjfbjfb
tqtqtqtqtq
cdocdocdocdocdo
imgimgimgimg
zxzxzxzxzx

output:

168
13
4
5
1
1
3
4
1
3

result:

ok 10 numbers

Test #9:

score: 5
Accepted
time: 3ms
memory: 4608kb

input:

10
sssssssssssssssssssss
wawawawawawawawa
xlexlexlexlexlexlexle
cwqfcwqfcwqfcwqfcwqfcwqfcwqf
dappidappidappidappidappi
biwtbbiwtbbiwtbbiwtb
ipdbipdbipdbipdb
oyqjoyqjoyqjoyqj
miqozmiqozmiqozmiqoz
ofqgofqgofqgofqg

output:

330
22
18
23
14
3
1
1
1
1

result:

ok 10 numbers

Test #10:

score: 5
Accepted
time: 4ms
memory: 4448kb

input:

10
zzzzzzzzzzzzzzzzzzzzzzzzzzz
icicicicicicicicicicic
saasaasaasaasaasaasaa
znunznunznunznunznun
ttfhhttfhhttfhhttfhhttfhh
fqxqblfqxqblfqxqblfqxqblfqxqbl
xxpruxxpruxxpruxxpru
mpheqsmpheqsmpheqsmpheqs
ptvbemqptvbemqptvbemqptvbemq
nxykqknxykqknxykqknxykqk

output:

728
70
36
5
26
7
5
1
1
1

result:

ok 10 numbers

Test #11:

score: 5
Accepted
time: 3ms
memory: 4596kb

input:

10
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
ibibibibibibibibibibibibibibibibibibibibibibibib
xinxinxinxinxinxinxinxinxinxinxin
ivlwivlwivlwivlwivlwivlw
cxrvucxrvucxrvucxrvucxrvucxrvucxrvucxrvucxrvu
jzqfmgjzqfmgjzqfmgjzqfmgjzqfmg
nqctlysnqctlysnqctlysnqctlysnqctlysnqctlysnqctlys
kuizuntnkuizuntnkuizuntnkuizu...

output:

1240
946
100
11
76
7
38
9
18
1

result:

ok 10 numbers

Test #12:

score: 5
Accepted
time: 3ms
memory: 4420kb

input:

10
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
dvdvdvdvdvdvdvdvdvdvdvdvdv
jhyjhyjhyjhyjhyjhyjhyjhyjhy
dkbjdkbjdkbjdkbjdkbjdkbjdkbjdkbj
ezlbtezlbtezlbtezlbtezlbtezlbtezlbtezlbt
efwduoefwduoefwduoefwduoefwduoefwduoefwduo
eqgdlgxeqgdlgxeqgdlgxeqgdlgxeqgdlgxeqgdlgx
mwuoqleamwuoqleamwuoqleamwuoqlea
gwcbhodfpgwcb...

output:

1632
125
48
38
46
33
17
1
1
5

result:

ok 10 numbers

Test #13:

score: 5
Accepted
time: 3ms
memory: 4608kb

input:

10
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
xwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxwxw
rslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrslrsl
iimeiimeiimeiimeiimeiimeiimeiimeiimeiimeiimeiime...

output:

25585
6391
1386
1014
876
567
62
118
33
86

result:

ok 10 numbers

Test #14:

score: 5
Accepted
time: 2ms
memory: 4604kb

input:

10
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
ozozozozozozozozozozozozozozozozozozozozozozozozozozozozozozozoz
ysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysvysv
ipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbdipbd
x...

output:

19019
2360
540
1826
110
7
511
118
132
53

result:

ok 10 numbers

Test #15:

score: 5
Accepted
time: 2ms
memory: 4424kb

input:

10
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
vzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvzvz
yzkyzkyzkyzkyzk...

output:

155155
18445
7600
13475
3328
72
114
37
17
6

result:

ok 10 numbers

Test #16:

score: 5
Accepted
time: 0ms
memory: 4352kb

input:

10
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
bxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbxbx...

output:

281295
48503
26100
13475
20516
80
72
59
21
26

result:

ok 10 numbers

Test #17:

score: 5
Accepted
time: 2ms
memory: 4424kb

input:

10
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...

output:

1391040
981179
345415
50677
52576
227
28
413
144
50

result:

ok 10 numbers

Test #18:

score: 5
Accepted
time: 2ms
memory: 4428kb

input:

10
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

38263590
33623065
4070400
510708
624588
2102
1074
299
408
1538

result:

ok 10 numbers

Test #19:

score: 5
Accepted
time: 5ms
memory: 4328kb

input:

10
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

245030555
46877978
4884100
14318590
12858978
5063
5381
7598
4729
5228

result:

ok 10 numbers

Test #20:

score: 5
Accepted
time: 87ms
memory: 4608kb

input:

10
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

563349754956
161455324997
76621205738
70150901846
40842068960
6056659
2820346
3357795
2628223
10884

result:

ok 10 numbers

Extra Test:

score: 0
Extra Test Passed