Hi all,
I tried running the following code in python3.6
PYTHON-3.6: CodeChef: Practical coding for everyone
It gave TLE for two test cases. One friend suggested to run the same code in pypy-3. But in that i am getting RE(SEGV). Any help would be appreciated!
PYPY3: CodeChef: Practical coding for everyone
There are at least two problems here.
-
Recursion is slow. This probably is enough to give you the TLE. It isnβt too bad to replace it with a while loop with the same logic.
-
Print is slow. Also probably enough for a TLE on the biggest test cases. You should only use it once to output the entire result rather than 1000000 times if one of the cases was 1000000. There are two simple ways to make something to output by concatenating a list L of integers:
out = ''.join(map(str,L))
Alternatively, the slightly less fancy
def ltoi(lis):
res=0
for x in lis:
res*=10
res+=x
return res
out = str(ltoi(L))
1 Like
@coulson72, Thanks a lot.
using out = ββ.join(map(str,L)) helped me to get over the TLE issues.