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

Автор sigma_g, история, 7 лет назад, По-английски

Problem: https://mirror.codeforces.com/contest/245/problem/H

My solution: https://mirror.codeforces.com/contest/245/submission/49911945
Editorial solution: https://mirror.codeforces.com/contest/245/submission/2622404

Both of the codes look exactly the same, and have the same logic. Yet mine is TLE. Could anyone please help me understand why that is the case?

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

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

I guess your solution is not the problem, since the one from the editorial also gives TLE.

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

Just swap cin, cout to scanf, printf. Editorial solution takes TLE too in C++11(14, 17). Maybe old C++ was faster xD.

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

Change endl to "\n" , endl does not tie the output,so your cout.tie() is ineffective.

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

Btw your line cout.tie(0) doesn't do anything. By default cin is tied to cout to guarantee that cout will be flushed before doing input reading, which is something you would want solving interactive problems. But cout is by default not tied to anything, so doing cout.tie(0) doesn't change anything.