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

×

TLE error in the problem

I am not able to remove TLE error from this. Here are the original constraints for the problem. 1≤T≤1,000 1≤N≤105 1≤Ai≤N for each valid i the sum of N over all test cases does not exceed 2⋅10^5.

def happy(L):
for i in range(1,len(L)-1):
    j=i+1
    while j<len(L):
        if L[i]==L[j]:
            if str(i) in L and str(j) in L:
                return "Truly Happy"
        j=j+1
return "Poor Chef"

x=int(input()) list=[] for i in range(x): y=int(input()) z=input().split() z.insert(0,0.3) list.append(z) for i in list: print(happy(i))

Sub-Task Task # Result (time) 1 0 AC (0.020000) Subtask Score: 27.00% Result - AC 2 1 AC (0.020000) 2 2 TLE (5.010000) 2 3 TLE (5.010000) Subtask Score: 0.00% Result - TLE Total Score = 27.00%

I have tried to think about other algorithms but cant find better than this. Maybe problem lies in the input part, which increases time.

asked 08 Nov, 14:07

kashin_koji's gravatar image

2★kashin_koji
-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:

×688
×481

question asked: 08 Nov, 14:07

question was seen: 38 times

last updated: 08 Nov, 14:07