CodeJam Round B Robot Path Decoding

Правка en1, от ritik652000, 2020-04-20 07:33:37

for _ in range(int(input())): p = input() a,b = 1,1 con = [] oper = [] i = 0 while i<len(p): if(p[i]==')'): j = oper.pop() a*=j b*=j a+=con[-1][0] b+=con[-1][1] con.pop() elif(p[i]=='E'): a+=1 elif(p[i]=="N"): b-=1 elif(p[i]=="S"): b+=1 elif(p[i]=="W"): a-=1 else: oper.append(int(p[i])) con.append([a,b]) a,b = 0,0 i+=1

i+=1
if(a<1):
    a = 1000000000+a
if(b<1):
    b = 1000000000+b

a = a%1000000000
b = b%1000000000
if(a==0):
    a = 1000000000
if(b==0):
    b = 1000000000    

print("Case #",_+1,": ",sep = "",end = "")
print(a,b)

Can someone please tell me why my O(N) approach got TLE. Thankyou

Теги #googlekickstart, #tle, #python3

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский ritik652000 2020-04-20 14:59:55 14
en2 Английский ritik652000 2020-04-20 07:47:45 443 Tiny change: 'put())):\n\n ' -> 'put())):\n '
en1 Английский ritik652000 2020-04-20 07:33:37 1123 Initial revision (published)