Блог пользователя tanu38

Автор tanu38, история, 6 лет назад, По-английски

Hello everyone!

Recently while solving a question 313B (in Python3 ), Me and my friend observed that TLE comes when we directly iterate using input, but not when we store intput in a variable and then iterate.

Please explain the reason why this is happening!

Case 1: TLE occured a = input() w=[0] z,j =0,1 for i in range(1,len(a)): if a[i]==a[i-1]: z+=1 w.append(z) for i in range(int(input())): a,b = map(int,input().split()) print(w[b-1]-w[a-1])

Case 2: No TLE, got Accepted a = input() w=[0] z,j =0,1 for i in range(1,len(a)): if a[i]==a[i-1]: z+=1 w.append(z) t =int(input()) for i in range(t): a,b = map(int,input().split()) print(w[b-1]-w[a-1])

Полный текст и комментарии »

  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится