Page 1 of 1

Timus 1989. Subpalindromes

Posted: Fri Jan 31, 2014 8:54 pm
by doctorlai
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?