ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1123. Salary

RTE #10 where am i wrong??
Posted by thamizhkavingan 17 Aug 2018 21:04
def chk(m):
    for i in range(0, int(len(m)/2)):
        if m[i] != m[len(m)-i-1]:
            if m[i] > m[len(m)-i-1]:
                m[len(m)-i-1] = m[i]
            else:
                m[len(m)-i-1] = m[i]
                m = inc(m, len(m)-i-2)
                chk(m)
    return m
def inc(y, x):
    if y[x]<9:
        y[x] += 1
    else:
        y[x] = 0
        inc(y, x-1)
    return y
v = list(input())
l = list(map(int, v))
if(len(v)==1):
    print(v[0])
else:
    l = chk(l)
    print("".join(str(o) for o in l))
Re: RTE #10 where am i wrong??
Posted by thamizhkavingan 17 Aug 2018 21:22
I thought index reaching end may be a problem but that can never happen can it?,
TLE may be ok but why RTE???
Re: RTE #10 where am i wrong??
Posted by thamizhkavingan 25 Aug 2018 09:38
It is because of too many recursion i presume trying to find a work around...
thamizhkavingan wrote 17 August 2018 21:04
def chk(m):
    for i in range(0, int(len(m)/2)):
        if m[i] != m[len(m)-i-1]:
            if m[i] > m[len(m)-i-1]:
                m[len(m)-i-1] = m[i]
            else:
                m[len(m)-i-1] = m[i]
                m = inc(m, len(m)-i-2)
                chk(m)
    return m
def inc(y, x):
    if y[x]<9:
        y[x] += 1
    else:
        y[x] = 0
        inc(y, x-1)
    return y
v = list(input())
l = list(map(int, v))
if(len(v)==1):
    print(v[0])
else:
    l = chk(l)
    print("".join(str(o) for o in l))