| Task: | Period |
| Sender: | hugues.verlin |
| Submission time: | 2016-10-24 00:57:43 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | WRONG ANSWER | 0.06 s | details |
| #3 | WRONG ANSWER | 0.05 s | details |
| #4 | WRONG ANSWER | 0.04 s | details |
| #5 | WRONG ANSWER | 0.05 s | details |
| #6 | WRONG ANSWER | 0.05 s | details |
Compiler report
input/code.cpp: In function 'void computeZarray(std::string, int*)':
input/code.cpp:10:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < n; ++i) {
^
input/code.cpp:13:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (R < n && str[R - L] == str[R]) R++;
^
input/code.cpp:21:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (R < n && str[R - L] == str[R]) R++;
^
input/code.cpp: In function 'int main()':
input/code.cpp:43:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (Z[i] == s.length() - i) { cout << s.substr(0, i); }
^Code
#include <bits/stdc++.h>
using namespace std;
void computeZarray(string str, int *Z) {
size_t n = str.length();
int L, R, k;
L = R = 0;
for (int i = 1; i < n; ++i) {
if (i > R) {
L = R = i;
while (R < n && str[R - L] == str[R]) R++;
Z[i] = R - L;
R--;
} else {
k = i - L;
if (Z[k] < R - i + 1) Z[i] = Z[k];
else {
L = i;
while (R < n && str[R - L] == str[R]) R++;
Z[i] = R - L;
R--;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
string s;
cin >> s;
if (s.length() == 1) { cout << s << endl; }
else {
int Z[s.length()];
computeZarray(s, Z);
for (unsigned long i = 1; i < s.length(); i++) {
if (Z[i] > 0) {
if (Z[i] == s.length() - i) { cout << s.substr(0, i); }
cout << endl;
break;
};
}
}
return 0;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
| correct output |
|---|
| a |
| user output |
|---|
| a |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
| correct output |
|---|
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
| user output |
|---|
| (empty) |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| nabvmrnenabvmrnenabvmrnenabvmr... |
| correct output |
|---|
| nabvmrne |
| user output |
|---|
| (empty) |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| fwqrbqnmobvwslpyfrlkrfwluaxyzk... |
| correct output |
|---|
| fwqrbqnmobvwslpyfrlkrfwluaxyzk... |
| user output |
|---|
| (empty) |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| ohicwwkhdoesqvsyemhdhubpvmqkre... |
| correct output |
|---|
| ohicwwkhdoesqvsyemhdhubpvmqkre... |
| user output |
|---|
| (empty) |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| gqzzocfzbuvfovbvamyflvcuuajzgu... |
| correct output |
|---|
| gqzzocfzbuvfovbvamyflvcuuajzgu... |
| user output |
|---|
| (empty) |
