| Task: | Palindrome |
| Sender: | smolse |
| Submission time: | 2016-10-24 15:47:05 +0300 |
| Language: | Python3 |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | TIME LIMIT EXCEEDED | -- | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | TIME LIMIT EXCEEDED | -- | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
Code
import fileinput
def longestPalindrome(s):
string = "#" + "#".join(s) + "#"
i = 0
mxb = 0
mxc = 0
p = [0] * len(string)
res = [0, 0]
while i < len(string):
if mxb > i:
p[i] = min(p[2 * mxc - i], mxb - i)
else:
p[i] = 1
while i - p[i] >= 0 and i + p[i] < len(string) and string[i - p[i]] == string[i + p[i]]:
p[i] += 1
if mxb < p[i] + i:
mxb = p[i] + i
mxc = i
if mxb - mxc > res[1] - res[0]:
res = [mxc, mxb]
i += 1
return "".join([x for x in string[2 * res[0] - res[1] + 1:res[1]] if x != '#'])
for line in fileinput.input(['-']):
seq = line
print(longestPalindrome(seq))
Test details
Test 1
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
| correct output |
|---|
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
| user output |
|---|
| (empty) |
Test 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| saippuakauppiassaippuakauppias... |
| correct output |
|---|
| saippuakauppiassaippuakauppias... |
| user output |
|---|
| (empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| yfsnqpzfxfhdnbozewnjtseeyktblk... |
| correct output |
|---|
| buevzveub |
| user output |
|---|
| (empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| oyyahdsjdwtziuwnmpjhshemvxodtc... |
| correct output |
|---|
| rrfaxafuttsospqnxbwaufpchwjaha... |
| user output |
|---|
| (empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| tcaxtmkrvjovwnhsqquwxuemckkmks... |
| correct output |
|---|
| xtmkrvjovwnhsqquwxuemckkmksqqj... |
| user output |
|---|
| (empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| mwuepokhcaykorctrxqvplhxbxjndd... |
| correct output |
|---|
| eyexbstwynwjbqjasyuaqrmckrgmki... |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
| correct output |
|---|
| bcbcbcbcbcbcbcbcbcbcbcbcbcbcbc... |
| user output |
|---|
| (empty) |
