QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291081#4224. 串MoRanSky100 ✓338ms173836kbC++232.0kb2023-12-26 04:46:552023-12-26 04:46:55

Judging History

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

  • [2023-12-26 04:46:55]
  • 评测
  • 测评结果:100
  • 用时:338ms
  • 内存:173836kb
  • [2023-12-26 04:46:55]
  • 提交

answer

// Skyqwq
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }

template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}

const int N = 5e5 + 5;

struct SAM{
	int len, nxt[26], link;
} t[N << 1];

int last, idx, n, sz[N << 1], pos[N << 1];

char s[N];

void inline init() {
	last = idx = 1;
}

vector<int> g[N << 1];

void inline clr() {
	for (int i = 1; i <= idx; i++) {
		for (int j = 0; j < 26; j++) t[i].nxt[j] = 0;
		t[i].link = t[i].len = pos[i] = sz[i] = 0;
		g[i].clear();
	}
	idx = last = 0;
}

void extend(int c) {
	int x = ++idx, p = last; sz[x]++; t[x].len = t[p].len + 1;
	while (p && !t[p].nxt[c]) t[p].nxt[c] = x, p = t[p].link;
	if (!p) t[x].link = 1;
	else {
		int q = t[p].nxt[c];
		if (t[p].len + 1 == t[q].len) {
			t[x].link = q;
		} else {
			int y = ++idx;
			t[y] = t[q];
			t[y].len = t[p].len + 1;
			while (p && t[p].nxt[c] == q) 
				t[p].nxt[c] = y, p = t[p].link;
			t[x].link = t[q].link = y;
		}
	}
	last = x;
}

int ans;

void dfs(int u) {
	for (int v: g[u]) {
		dfs(v);
		sz[u] += sz[v];
		if (pos[v]) {
			if (!pos[u]) pos[u] = pos[v];
			else chkMin(pos[u], pos[v]);
		}
	}
	if (sz[u] > 1) chkMax(ans, t[u].len + (n - pos[u]) / 2);
}

int main() {
	int T; read(T);
    while (T--) {
    	init();
    	scanf("%s", s + 1); n = strlen(s + 1);
    	ans = n / 2;
    	for (int i = 1; i <= n; i++) extend(s[i] - 'a'), pos[last] = i;
    	for (int i = 2; i <= idx; i++) g[t[i].link].pb(i);
    	dfs(1);
    	printf("%d\n", ans);
    	clr();
    }
    return 0;
}

详细

Test #1:

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

input:

5
wwgpdvdwwgpdvdwwgpdvdwwwvdwdww
imeoqomeomqomeommeoqomeomqomem
blmjcxblmjcxlmjlmjcxjcxblmjcxl
exzhdyzhddyzhdedyzhyzhddydyyzd
tsbosqtsbosqtsbossbosqtssqtsbb

output:

23
21
18
15
20

result:

ok 5 lines

Test #2:

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

input:

5
rmgmlkgmlkllklmlkgmgmlklklmlkm
fstnttfttfnttfttfttfttfttttftt
hxiykziykzixiykziyykzixiyiyyky
fbtnfwbtnffwbfbtnfwbtnffwwbtnw
yhdizazyhdidihdidihdizzazyyhdi

output:

17
17
18
21
17

result:

ok 5 lines

Test #3:

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

input:

4
skjnitkwybtcsfagbpslfxtijbwjqvskibxqwjmukwybtcsfagbbpslfxtijbwjqvskibxqwjmukwybtcsfagbpslfxtijbwjqvskibxqwjmukwybtcsfagbbpslfxtijbwjqvskibxqwjmukwybtcsfagbbpslukwybtcsfagbbpslfxtijbbbpslukwybtcsfaslfc
ssrpyzpwiydtayxmoddtqksdrhcavtsonldnmujuyzpwiydtayxmoddtqksdrhcavtsoniydtayxmoddtqksdrhwiydtayxmo...

output:

137
112
121
112

result:

ok 4 lines

Test #4:

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

input:

4
oupltnlcbcgntpnkbvktcbcpltnlcbcgpltnlcgpltngntpnlcbcgntpnkbvktcbcpltnlcbcgpltnlnlcbcgpltnlcgpltngntpnlcbcgntpnktngntpnlcbcgntpnkbvktcbcpltnlcbcgpltnlnlcbcgpltnlcgpltngntpnlcbcgntpnlcbcgntlcbcgntpnkbvn
nzmyzhhsoehahmorxpahsoehahmororxpahsoehahmhsoehahmmyzhhsoehahmhahsoehahmororxpahsoehahmhsoehahmmy...

output:

114
130
117
113

result:

ok 4 lines

Test #5:

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

input:

4
wwsqbwicfggaflmvdvegdkclrnybwwsqbwicfggafgdkclrnyaflmvdvegdkclrnybwwsqbwlrnybwwsqbwicfggafgdkclrnyaflmvdvegdkclrnybwwegdknybwwsqybwwsqbwlrnybwwsqbwicfggafgdkclrnyaflmvdvegdkclrnybqbwicfggafgdkclrnyafg
tgloxggsznuxqxggszxggszsznuxqxggszxggszggsznuxqxggsggsznuxqxggszxggszsznuxqxggszxggszggsznuxqxggs...

output:

111
120
112
106

result:

ok 4 lines

Test #6:

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

input:

3
ikcblmcsjillvojwymeimbaeipbhobwwnyaakcsvkghhusduehctjexrtaakewiruishkmewsleodhikrnfaternerxiqhamqutaiazbldrrmaddpidimwxsqwbgedswzowhovibaauncxsthwdvudokzpsfulbtbaapxlexrtaakewiruishkmewsleodhikrnfaternerxiqhamqutaiazbldrrmaddpidimwxsqwbgedswzowhovibaauncxsthwdvudokzpsfulbtbaapxlidimwxsqwbgedswzowh...

output:

638
610
568

result:

ok 3 lines

Test #7:

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

input:

3
gsxasrisfpretvfhxlwnysaarwkvizqrrntjecdltvqmsvvqgsdgkggdcszmtrfkfzwldzxnysgsxasrisfpretvfhxlwgsxasrisfpretvfhqrrntjecdltvqmsvvqgsdgkggdcszmtrfkfzwarwkvizqrrntjecdltvqmsvvqgsdgkggdcszmtrfkfzwldzxnysgsxasrisfpretvjecdltvqmsvvqgsdgkggdcszmtrfkfzwldzxnfkfzwldzxnysgsxasrisfpretvjecdltvqmsvvqgsdgkggdcsz...

output:

582
591
547

result:

ok 3 lines

Test #8:

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

input:

3
aekaabidsppfvwzguexdmycjcqqcxdmycjcqqycjcqexdmycjcqqcxdmycjcqqcxdmycjcqqycjcqevwzguexdmycjcqqcxdmyabidsppfvwzguexdmycjcqqcxdmycjcqqycjcqexdmycjcqqcxdmycjcqqcxdmycjcqqycjcqezguexdmycjcqqcxdmycjcqqycjcqexdmycjcqqcxdmycjcqqcxdmycjcqqycjcqevwzguexdmycjcqqcxdmyxdmycjcqqcxdmycjcqqycjcqexdmycjcqqcxdmycjc...

output:

539
563
520

result:

ok 3 lines

Test #9:

score: 5
Accepted
time: 221ms
memory: 103684kb

input:

4
fqbsybwtrauafctwxtzxmhmelxssvxxapauncqgvqcwxfptcktzyanenlxfguejjhdzjufgmicmptfrfasgcgkqrjxzfcipjoqukvawffkuaqniqgotoylhiignmrevhwrruupzzawbqljitxdhyooixxxlqejxaaouufwvfuzxhigbilkiazqzypkovtnwwbssiqookpnsxvvhhfpjghkezwuushsoilgtbwholuilqdszikiptsvuoqpgxhwisfbwbkkpesawxuvhgfycxuwoklwjvtrpaulbexqlrsh...

output:

187457
187894
187356
187301

result:

ok 4 lines

Test #10:

score: 5
Accepted
time: 100ms
memory: 54112kb

input:

105
iiqnrmmdztbfxwmieuflzvuqveboseucomrfagkbzohyktiqnnbpkyhgciuwoqacerjgxthwjqxtkfjzvnqfnxlpfhnvznxfeglecvcllzhxhszcfphsnvjuewqelnlswxwauylfaufhnejutsngnybuxtaiglaekyeexsmxmrezvpuohjxxjatgttrbetirsmvrehqtawuvlqmuzltllmtgfmjmgrdagytkijfkfagsqumsfidsuyyclhotbrvhrotbzzmgbuyromlvuqnrpntauhvxaqereyvfzjla...

output:

5001
5001
5001
5001
50001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5002
5001
5001
5001
5001
5001
50001
5001
5001
5001
5002
5001
5001
5001
5001
5002
5001
50001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
5001
50...

result:

ok 105 lines

Test #11:

score: 5
Accepted
time: 209ms
memory: 115856kb

input:

1000001
s
o
k
g
r
z
l
d
z
i
n
u
d
j
i
o
k
b
o
s
h
y
w
y
u
k
v
p
d
f
e
x
v
q
d
o
p
r
s
o
z
f
i
e
r
q
s
b
u
i
w
b
g
u
b
a
e
w
p
j
e
v
g
z
l
l
o
c
c
i
q
b
n
b
h
g
t
z
i
p
h
e
s
q
a
u
s
e
s
i
n
w
f
t
y
t
g
o
v
j
w
o
m
l
r
u
s
k
t
c
c
d
i
u
t
i
q
l
m
j
v
b
f
d
w
f
w
c
t
r
l
p
h
y
b
y
u
v
l
n
x
n
s
f
j
n
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000001 lines

Test #12:

score: 5
Accepted
time: 27ms
memory: 38828kb

input:

110
rxxioshkbndigoxntdcejhvoskbndigoxntdcejgoxntdcejhvoskbndigoxbndigoxntdcejhvoskbndigoxntdccejhvoskbndigogoxntdcejgoxntdcejhvoskbndigoxbnejgoxntdcejhvoskbndigoxbndigoxntdcejhvoskbndigoxntdccejhvoskbndigogoxntdcejgoxntdcejhvosxntdcejhvoskbndigoxbndigoxntdcejhvoskbndigoxntdccejhvoskbndigogoxntdcejgo...

output:

629
577
663
560
622
537
11746
11759
625
966
595
537
989
567
539
544
578
562
536
600
572
521
19986
979
952
597
632
957
552
605
980
535
566
559
963
12740
629
548
571
988
641
14356
558
571
598
982
539
645
580
586
967
995
966
597
623
961
589
988
594
582
638
606
11243
954
604
558
588
579
559
627
547
590
...

result:

ok 110 lines

Test #13:

score: 5
Accepted
time: 22ms
memory: 42840kb

input:

105
jlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizo...

output:

993
674
578
520
563
621
39987
623
562
551
650
631
541
598
976
663
578
600
984
556
652
996
560
596
672
964
684
972
613
990
596
551
39989
592
579
552
971
587
958
976
640
641
650
967
997
570
591
523
644
571
951
598
645
601
670
556
536
663
596
719
26336
581
618
658
544
662
22008
633
979
540
677
539
965
...

result:

ok 105 lines

Test #14:

score: 5
Accepted
time: 30ms
memory: 53780kb

input:

5
xsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmn...

output:

59993
31805
31649
59999
35053

result:

ok 5 lines

Test #15:

score: 5
Accepted
time: 23ms
memory: 34856kb

input:

30
qqgcvqshumzfapruaztsztbkdhknlqmegsgekylgmkmobfjceeuezxqcebpqrduyxccjcpqqbefdlqfpubvvymxfnovetrestidxxvnbzsekilcemxbmjaryqofjfjdashxrclsefyqqjswxsykbydcrshczqgaknzermwvsvmkgegeygqahteynlandipovosnbqkvnwfudnabuqddlhbzsdowmfmjtgywwjtmhaikoimkapplzsmrxcpjhdvdjtbievwmxewlokxocobbgoueqkpypkdzgejmzfyxjx...

output:

5409
6422
9965
6171
9985
5656
6137
9965
5246
5788
6213
5511
9988
9994
9991
6384
9982
6431
9993
5763
6489
5902
5343
5847
5849
6573
5863
5737
6460
6527

result:

ok 30 lines

Test #16:

score: 5
Accepted
time: 338ms
memory: 173836kb

input:

3
pounzdtkokaonqyllykjhhycqxdmmwndkjqlnlxbwzqlpqwcpjnysncilfxzdkenuwbjhakfacsptrukajksxnbksyjykplglopupccpgugzlcllmwgjjhtdhebttpcgfrcuvelczudmyrakngvypqdyufrpwtxbnaykelodhusglsqayoypebnzigqgcokrokbuvsadmsjzkbzkpzzucovnwltyzdrpnvmlnmqbezaqazcsybmcrhpnsjouofleczrplhqrgqhirjarmoudvjtqsjmjqzptzgimnbetrl...

output:

283790
303401
286117

result:

ok 3 lines

Test #17:

score: 5
Accepted
time: 148ms
memory: 107704kb

input:

36
bqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrg...

output:

49988
10658
28088
11977
49994
11321
13086
49974
12836
31204
11573
30769
29147
10648
12611
11999
49983
499970
13419
11724
19956
19953
29731
11345
12438
12680
19973
12970
19992
19986
30847
11087
10522
11308
10609
12006

result:

ok 36 lines

Test #18:

score: 5
Accepted
time: 184ms
memory: 160924kb

input:

36
ueuhiuuxbkqmcjrkbkknbuogliigucooglvofroicgveqoqtacgcwukjfuszwgpermvydlhfreljsdcuhkwdfgpmbhlznaefmbfrmmzdsmpmqrhxcddjmsvpziookuvyvbpjpqnideuvvbuzhxktrhkspahzvczsdpcvfrdkvxfszauizebrmljdlsfixedavhxbyalvyrpztjhsqkleljsdcuhkwdfgpfreljsdcuhkwdfgpmbhlznaefmbfrmmzdsmpmqrhxcddjmsvpziookuvyvbpjpqnideuvvbu...

output:

11223
11643
12012
19963
12651
31459
14468
28087
33112
19974
19950
19997
49982
49993
13154
19962
277645
10927
49970
12457
29707
26432
11485
11694
19977
12699
13358
19973
10948
11629
29009
19964
27385
12772
11344
10920

result:

ok 36 lines

Test #19:

score: 5
Accepted
time: 122ms
memory: 111516kb

input:

400001
ggg
eee
hhh
ppp
eee
nnn
hhh
aaa
nnn
uuu
xxx
ddd
ttt
sss
jjj
fff
ccc
ddd
aaa
xxx
vvv
mmm
qqq
bbb
qqq
uuu
bbb
ggg
mmm
qqq
ccc
hhh
nnn
yyy
hhh
qqq
fff
www
xxx
uuu
iii
ggg
nnn
rrr
sss
aaa
eee
vvv
iii
eee
vvv
www
qqq
ddd
qqq
rrr
qqq
xxx
ppp
yyy
nnn
bbb
uuu
bbb
yyy
aaa
ttt
www
mmm
lll
qqq
ggg
zzz
b...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 400001 lines

Test #20:

score: 5
Accepted
time: 260ms
memory: 170344kb

input:

27
xtahmwzugvrelqyihbryeggyvqgliwxirxrdvtxbopgahekrhbpnixmfpuryqqiipznksnljetllzvehwvugsimiffivvsfktvumihxmdixcdelbziiuquevzotugagzvcndjkposprxtczumhoddsacivyowgqridxtqmikdbiyfhtsqhxtczxkvxbtfrknwjiowszbthabqtticsbgratmzufenstlbbczubdpkdqcylkcdnjvnejoarsplnaoocqkftcpwstwgdyjqhgfnstnjncuafkrhadptfgra...

output:

12118
12260
19991
11406
13637
19972
19986
11246
12946
19984
11974
12449
12283
12022
12063
300783
11398
10957
11564
280619
12088
19972
11514
11971
11448
11649
12875

result:

ok 27 lines

Extra Test:

score: 0
Extra Test Passed