imasnegi's blog

By imasnegi, history, 5 years ago, In English

This code I submitted for question d: Euler Cycle, but this is getting Time Limit Exceeded. May anyone help me to know why?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
Rev. 2   Vote: I like it +15 Vote: I do not like it

for(int j = left; j <= right; j++)

The variables left and right are long long values and might have a value bigger than $$$2^{31}$$$. There will be overflows when you set int j = left and the loop will take a really long time to complete.

Anyway you should learn to debug such errors by yourself, it's hard to get anywhere depending on others like that. You can see the test case, it's not big. Then you can use a debugger or just print statements to isolate the code that takes so long. Etc.