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

×

why i am getting TLE after 1st test cases

september long challenge. i think my code is right but why i am getting TLE after 1st test cases. plz suggest me . following is my code link https://www.codechef.com/viewsolution/15327071

and link for question is https://www.codechef.com/SEPT17/problems/SEACO

This question is marked "community wiki".

asked 13 Sep '17, 23:21

jp96612's gravatar image

1★jp96612
11
accept rate: 0%

your approach is not efficient enough to solve this problem without getting TLE, I'm having the same problem :(

(14 Sep '17, 00:51) kunnu1202★

Look the problem isn't that your code is not right, it's just that its is not efficient. I mean your time complexity is O(n*n) which takes you out of the time limit provided in the question. You need to think of of O(nlogn) solution. If you dont know about segment trees ,google it and learn it.

Feel free to ask if you don't get what I am talking about!

link

answered 14 Sep '17, 08:25

slugger's gravatar image

1★slugger
544
accept rate: 25%

Well, there's a simpler O (N+M) approach to solve this question if u are comfortable with difference arrays.

Following Link to my explanation..

Feel free to ask anything... Please upvote

link

answered 14 Sep '17, 11:09

taran_1407's gravatar image

6★taran_1407
3.9k2892
accept rate: 22%

your code's time complexity is O(N*N) and n is quite large so it's giving u an TLE. Try solving it through segmented trees/ bit (fenwick trees).

You can follow this link, this video is kind of nice, give it a look

https://www.youtube.com/watch?v=ZBHKZF5w4YU

link

answered 05 Oct '17, 00:48

ricksr's gravatar image

4★ricksr
162
accept rate: 6%

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:

×2,351
×367
×164

question asked: 13 Sep '17, 23:21

question was seen: 324 times

last updated: 05 Oct '17, 00:48