Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

lazy_wallflower's blog

By lazy_wallflower, history, 2 years ago, In English

In the problem D of recent Edu round, I used binary search to solve the problem, but i'm not able to figure out where the TLE is, please help me find out.

276695555 2004D - Colored Portals

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

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

For this problem, O(nlogn) with bad constant factor could TLE. However, if you add this line of code right after you declare main(): ios_base::sync_with_stdio(false); cin.tie(NULL); Using the above code will make the input factor and can make the code significantly faster.

Take a look at my submission of your code with the added line: 277182525 It gets 1842ms with AC.

Feel free to also look at my O(n) solution which passes relatively comfortably (since 1842 ms is still a lot): 276595217

Note that the pragma that I include in the top could also make your code faster. These things might be a good idea for you to include in your template.

Hope this helps!

»
2 years ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Do not use map. Instead use vector of vector for the mp variable.

»
2 years ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Replacing endl with \n also improves performance. I had to do it some times to not get TLE. I have seen reductions as big as 8x with this (from 1130ms to 134ms), but it'll vary on problems and tests.