Submission details
Task:Longest palindrome
Sender:aalto26iw_007
Submission time:2026-11-04 17:13:01 +0200
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.04 sdetails
#20.04 sdetails
#30.06 sdetails
#40.06 sdetails
#50.06 sdetails
#60.06 sdetails
#70.06 sdetails
#80.06 sdetails
#90.04 sdetails
#100.04 sdetails
#110.05 sdetails
#120.04 sdetails
#130.04 sdetails
#140.04 sdetails
#150.04 sdetails
#160.05 sdetails

Code

import sys
inp = sys.stdin.read().strip()



'''total = 0
for i in inp:
    if total <0 :
        print("not correct")
    if i == "(":
        total+=1
    elif i== ")":
        total-=1
    else:
        print(i)
        print("error")
        exit()
print(total == 0)
'''
n = len(inp)
dp = [0 for _ in range(len(inp))]

ind = 0
lgth = 0
'''
def isvalid(s):
    total = 1 
    length = 1
    for i in range(1,len(s)):
        total = total'''


#)))((()))(((
for i in range(n):
    if inp[i] == "(":
        total = 1
        length= 1
        for k in range(i+1,n):
            total = total + 1 if inp[k] == "(" else total -1
            #print(i,k,total)
            if total < 0 :
                #total-=1
                break
            else :
                length+=1

        if total > 0 :
            length -= total
       
        if length > lgth :
            ind = i 
            lgth = length
    #print("with",i,"max is",lgth)
if lgth < 2 :
    print(-1)
    exit()


print(inp[ind:ind+lgth])



Test details

Test 1

Verdict:

input
aaaaaaaaaa

correct output
aaaaaaaaaa

user output
-1

Test 2

Verdict:

input
ababababab

correct output
ababababa

user output
-1

Test 3

Verdict:

input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

user output
-1

Test 4

Verdict:

input
ababababababababababababababab...

correct output
ababababababababababababababab...

user output
-1

Test 5

Verdict:

input
aztdvxzjwxtrludymvpradgbdpgnrq...

correct output
aztdvxzjwxtrludymvpradgbdpgnrq...

user output
-1

Test 6

Verdict:

input
vvfigwwsyxbukedgcfyibvtbclybud...

correct output
vvfigwwsyxbukedgcfyibvtbclybud...

user output
-1

Test 7

Verdict:

input
abaabaaaaaaabaababbbbbbabaaabb...

correct output
babbbabbbaabbbbaabbbbbbbbaabbb...

user output
-1

Test 8

Verdict:

input
txolestmgyepwrpofxyesjtsfkhjac...

correct output
yxnbaabnxy

user output
-1

Test 9

Verdict:

input
ihpohpzoffel

correct output
ff

user output
-1

Test 10

Verdict:

input
flexflexvpqxierullgcfckjqflexf...

correct output
cfc

user output
-1

Test 11

Verdict:

input
aabbabaabbaababbabaababbaabbab...

correct output
abaababbaabbabaababbabaabbaaba...

user output
-1

Test 12

Verdict:

input
obsession

correct output
ses

user output
-1

Test 13

Verdict:

input
abcxcbaxcba

correct output
abcxcba

user output
-1

Test 14

Verdict:

input
zzabc

correct output
zz

user output
-1

Test 15

Verdict:

input
aaccaabbaaccaaccaabbaaccaa

correct output
aaccaabbaaccaaccaabbaaccaa

user output
-1

Test 16

Verdict:

input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

user output
-1