Task: | Z-array |
Sender: | aalto2024i_005 |
Submission time: | 2024-10-31 21:21:12 +0200 |
Language: | C++ (C++17) |
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.09 s | details |
#7 | ACCEPTED | 0.13 s | details |
#8 | ACCEPTED | 0.09 s | details |
#9 | ACCEPTED | 0.08 s | details |
#10 | ACCEPTED | 0.09 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.09 s | details |
#13 | ACCEPTED | 0.09 s | details |
Compiler report
input/code.cpp: In function 'void solve()': input/code.cpp:28:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 28 | for (int i = 1; i < zArr.size(); i++) | ~~^~~~~~~~~~~~~ input/code.cpp:35:22: 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] == s[comp]) | ~~^~~~~~~~~~ input/code.cpp:54:30: 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] 54 | while (comp1 < s.size() && s[comp1] == s[comp2]) | ~~~~~~^~~~~~~~~~ input/code.cpp:66:23: warning: comparison of integ...
Code
#include <iostream> #include <vector> #include <array> #include <string> #include <algorithm> #include <numeric> #include <unordered_map> #include <unordered_set> #include <set> #include <queue> #include <climits> #include <cmath> #include <functional> #include <type_traits> #include <bitset> #define int long long using namespace std; void solve() { string s; cin >> s; int l = 0, r = 0; vector<int> zArr(s.size()); zArr[0] = s.size(); for (int i = 1; i < zArr.size(); i++) { if (i > r) { // Use naive approach int comp = 0; r = i; while (r < s.size() && s[r] == s[comp]) { r++; comp++; } r--; l = i; zArr[i] = r-l+1; } else { // Case 2 if (zArr[i-l] < r-i+1) zArr[i] = zArr[i-l]; else { // Case 3 int comp1 = r+1; int comp2 = comp1 - i; while (comp1 < s.size() && s[comp1] == s[comp2]) { comp1++; comp2++; } r = comp1 - 1; l = i; zArr[i] = r-l+1; } } } for (int i = 0; i < zArr.size(); i++) cout << zArr[i] << " "; } signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int t = 1; //cin >> t; while (t--) { solve(); } }
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... |