You are not logged in. Please login at www.codechef.com to post your questions!

×

DOWNLOAD: Getting compile time exceed

import sys
N = input()
N=int(N)
T= []
for i in range(0,N):
    i = input()
    i=i.split()
    T.append(i[0])
    T.append(i[1])
Q=input()
Q=int(Q)
q=[]
t=[]
for j in range(0,Q):
    j=input()
    j=j.split()
    q.append(int(j[0]))
    temp=int(j[0])
    k=1
    while(temp):
        t.append(int(j[k]))
        temp-=1
        k+=1
temp=Q
g=0
while(temp):
    count=0
    a=[]
    for n in range(0,N):
        a.append(0)
    for m in range(0,q[Q-temp]):
        for o in range(0,N):
            if(int(T[2*o])<=t[g]):
                if(int(T[(2*o)+1])>=t[g]):
                    if(a[o]==0):
                        a[o]=1
                        count+=1
        g+=1
    print(count)
    temp-=1
del q
del t
del T
del N

What can I do reduce my compile Time, pls suggest...i a beginner to python

asked 30 Jun '12, 22:31

sarveshgpt1991's gravatar image

2★sarveshgpt1991
1222
accept rate: 0%

edited 10 Jul '12, 11:11

admin's gravatar image

0★admin ♦♦
19.8k350498541


It' NOT compile time, but runtime time. Simply your algorithm is slow. You are using three for loops, so the complexity of the algorithm is something like O(N*q[Q-1]), so for N = 10^5 and q[Q-1] = 10^9 it will run for 10^5 seconds - that's why you are getting TLE...

link

answered 02 Jul '12, 15:41

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

hiii, sachin

link

answered 08 Apr '16, 15:04

vickysadh's gravatar image

0★vickysadh
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×521
×204
×19
×8

question asked: 30 Jun '12, 22:31

question was seen: 1,333 times

last updated: 08 Apr '16, 15:04