| Task: | Z-array |
| Sender: | aalto26ih_037 |
| Submission time: | 2026-11-01 13:55:49 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
| #6 | ACCEPTED | 0.10 s | details |
| #7 | ACCEPTED | 0.10 s | details |
| #8 | ACCEPTED | 0.10 s | details |
| #9 | ACCEPTED | 0.10 s | details |
| #10 | ACCEPTED | 0.10 s | details |
| #11 | ACCEPTED | 0.00 s | details |
| #12 | ACCEPTED | 0.10 s | details |
| #13 | ACCEPTED | 0.10 s | details |
Compiler report
input/code.cpp: In function 'void zfunc(std::string)':
input/code.cpp:29:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0;i<s.size();i++)z[i]=0;
| ~^~~~~~~~~
input/code.cpp:32:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=1;i<s.size();i++){
| ~^~~~~~~~~
input/code.cpp:35:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | while(r<s.size() && s[r-l]==s[r])r++;
| ~^~~~~~~~~
input/code.cpp:46:24: warning: comparison of integer expressions of different signedness: 'long...Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define die(x) return cout << x << endl, 0
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define SZ(x) ((int)(x).size())
typedef long double ld;
typedef long long ll;
int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
int to_int(string sconvert){stringstream geek(sconvert);int xconvert = 0; geek >> xconvert; return xconvert;}
const int MAXN=2e6+30,MAX_LOG=40,MOD=1e9+7,INF=1e9;
const double PI = acos(-1);
int mod(int x) { return (x % MOD + MOD) % MOD; }
int power(int x,int y){
if(y==0)return 1;
int c=power(x,y/2);
c=(c*c)%MOD;
if(y%2)c=(c*x)%MOD;
return c;
}
int z[MAXN];
void zfunc(string s){
for(int i=0;i<s.size();i++)z[i]=0;
z[0]=s.size();
int l=0,r=0;
for(int i=1;i<s.size();i++){
if(r<i){
l=r=i;
while(r<s.size() && s[r-l]==s[r])r++;
z[i]=r-l;
r--;
}
else{
int k=i-l;
if(z[k]<r-i+1){
z[i]=z[k];
}
else{
l=i;
while(r<s.size() && s[r-l]==s[r])r++;
z[i]=r-l;
r--;
}
}
}
}
int MAIN(){
string s;
cin>>s;
zfunc(s);
for(int i=0;i<SZ(s);i++){
cout<<z[i]<<" ";
}
cout<<endl;
return 0;
}
int32_t main(){
IOS;
int t=1;
// cin>>t;
while(t--)MAIN();
return 0;
}
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... |
