ritik652000's blog

By ritik652000, history, 2 months 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.com/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

Read more »

 
 
 
 
  • Vote: I like it
  • -9
  • Vote: I do not like it

By ritik652000, history, 2 months ago, In English

Can someone please help me, I got TLE on O(N) on 714B?

mod = 10**9 + 7
for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))
    count = arr[0]
    f = 1
    for i in range(1,n):
        count&=arr[i]
        f*=i
    f//=(n-1)
    t = arr.count(count)
    p = 1
    if(t<=1):
        print(0)
    else:
        
        p = t*(t-1)
        re = p*f
        print(re%mod)

Read more »

 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

By ritik652000, history, 14 months ago, In English

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

Code

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)

Read more »

 
 
 
 
  • Vote: I like it
  • -3
  • Vote: I do not like it