Task: | Z-array |
Sender: | esya_rae |
Submission time: | 2024-11-04 14:53:54 +0200 |
Language: | Python3 (PyPy3) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.04 s | details |
#2 | ACCEPTED | 0.04 s | details |
#3 | ACCEPTED | 0.05 s | details |
#4 | ACCEPTED | 0.04 s | details |
#5 | ACCEPTED | 0.04 s | details |
#6 | ACCEPTED | 0.27 s | details |
#7 | ACCEPTED | 0.27 s | details |
#8 | ACCEPTED | 0.32 s | details |
#9 | ACCEPTED | 0.28 s | details |
#10 | ACCEPTED | 0.27 s | details |
#11 | ACCEPTED | 0.04 s | details |
#12 | ACCEPTED | 0.27 s | details |
#13 | ACCEPTED | 0.28 s | details |
Code
def z_array(s): n = len(s) z = [-1] * n x, y = 0, 0 for i in range(1, n): z[i] = max(0, min(z[i - x], y - i + 1)) while i + z[i] < n and s[z[i]] == s[i + z[i]]: x = i y = i + z[i] z[i] += 1 z[0] = n return z s = input() print(*z_array(s))
Test details
Test 1
Verdict: ACCEPTED
input |
---|
aaaaaaaaaa |
correct output |
---|
10 9 8 7 6 5 4 3 2 1 |
user output |
---|
10 9 8 7 6 5 4 3 2 1 |
Test 2
Verdict: ACCEPTED
input |
---|
ababababab |
correct output |
---|
10 0 8 0 6 0 4 0 2 0 |
user output |
---|
10 0 8 0 6 0 4 0 2 0 |
Test 3
Verdict: ACCEPTED
input |
---|
aabababaaa |
correct output |
---|
10 1 0 1 0 1 0 2 2 1 |
user output |
---|
10 1 0 1 0 1 0 2 2 1 |
Test 4
Verdict: ACCEPTED
input |
---|
ahtqqkhrrn |
correct output |
---|
10 0 0 0 0 0 0 0 0 0 |
user output |
---|
10 0 0 0 0 0 0 0 0 0 |
Test 5
Verdict: ACCEPTED
input |
---|
mqdozmqdoz |
correct output |
---|
10 0 0 0 0 5 0 0 0 0 |
user output |
---|
10 0 0 0 0 5 0 0 0 0 |
Test 6
Verdict: ACCEPTED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
1000000 999999 999998 999997 9... |
user output |
---|
1000000 999999 999998 999997 9... |
Test 7
Verdict: ACCEPTED
input |
---|
ababababababababababababababab... |
correct output |
---|
1000000 0 999998 0 999996 0 99... |
user output |
---|
1000000 0 999998 0 999996 0 99... |
Test 8
Verdict: ACCEPTED
input |
---|
baaaabbabaabbbbaaaabbbababaaba... |
correct output |
---|
1000000 0 0 0 0 1 2 0 3 0 0 1 ... |
user output |
---|
1000000 0 0 0 0 1 2 0 3 0 0 1 ... |
Test 9
Verdict: ACCEPTED
input |
---|
ltpbdybvcpychbsplyonjfmdtsnqwt... |
correct output |
---|
1000000 0 0 0 0 0 0 0 0 0 0 0 ... |
user output |
---|
1000000 0 0 0 0 0 0 0 0 0 0 0 ... |
Test 10
Verdict: ACCEPTED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
1000000 99998 99997 99996 9999... |
user output |
---|
1000000 99998 99997 99996 9999... |
Test 11
Verdict: ACCEPTED
input |
---|
abaababaab |
correct output |
---|
10 0 1 3 0 5 0 1 2 0 |
user output |
---|
10 0 1 3 0 5 0 1 2 0 |
Test 12
Verdict: ACCEPTED
input |
---|
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz... |
correct output |
---|
1000000 499999 499998 499997 4... |
user output |
---|
1000000 499999 499998 499997 4... |
Test 13
Verdict: ACCEPTED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
1000000 147418 147417 147416 1... |
user output |
---|
1000000 147418 147417 147416 1... |