ritik652000's blog

By ritik652000, history, 4 years ago, In English

Can someone tell me why my solution is getting TLE in Educational Round 107C

its complexity is O(Q*Ai) Q <= 3*(10^5) Ai <= 50

Link to Ques = https://codeforces.me/contest/1511/problem/C

import math
a,b = map(int,input().split())
arr = list(map(int,input().split()))
brr = list(map(int,input().split()))
t = [0]*(max(arr)+1)
for i in range(a):
    if(t[arr[i]]==0):
        t[arr[i]] = i+1
for i in range(b):
    print(t[brr[i]],end = " ")
    for j in range(len(t)):
        if(t[j]<t[brr[i]]):
            t[j]+=1
    t[brr[i]] = 1
  • Vote: I like it
  • -9
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

It works for me: 112911897. Maybe you used CPython instead of PyPy? CPython is quite slow, PyPy is usually much faster.