maniratnagupta's blog

By maniratnagupta, history, 6 years ago, In English

Can you explian me where i am going wrong my solution is time limit exceeded at test 20 this is your solution::::::http://codeforces.com/contest/237/submission/35507431 this is my solution:::::http://codeforces.com/contest/237/submission/35571285

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

| Write comment?
»
6 years ago, # |
  Vote: I like it +2 Vote: I do not like it

The problem, friend, is in communism per se

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

The first solution you linked is linear in complexity with respect to input, whereas your solution is quadratic (O(N2)). This makes it do around 1010 operations in worst case and hence can't pass within time limit. As a thumb rule try analyzing your algorithm's Time Complexity before coding a solution. This is a good starting point to learn about analyzing complexity of your programs.