Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

Блог пользователя lazy_wallflower

Автор lazy_wallflower, история, 2 года назад, По-английски

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

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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

»
2 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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.