Timus 1989. Subpalindromes

Discussion on problems from different online judges e.g. Codeforces, Timus goes here.
doctorlai
Site Admin
Posts:44
Joined:Tue Jan 15, 2013 3:16 pm
Timus 1989. Subpalindromes

Post by doctorlai » Fri Jan 31, 2014 8:54 pm

http://acm.timus.ru/problem.aspx?space=1&num=1989

Code: Select all


s = list(raw_input())
n = int(raw_input())

def chk(s, i, j):
    while i <= j:
        if s[i] != s[j]:
            return False
        i += 1
        j -= 1
    return True

for i in xrange(n):
    ss = raw_input().split()
    if ss[0][0] == 'p':
        print 'Yes' if chk(s, int(ss[1]) - 1, int(ss[2]) - 1) else 'No'
    else:
       
        s[int(ss[1]) - 1] = ss[2]


The above Python code gets Time Limit Exceeded at Test 8..

any methods to make it faster? or is it impossible to get this accepted in Python?

Post Reply