Блог пользователя M-I

Автор M-I, история, 35 часов назад, По-английски

Today while upsolving this problem from the COMPFEST 18 Final on TLX I found something unexpected

I came up with a $$$O(N \log^2 N)$$$ solution which should have been fast enough for the given constraints My code was well optimize but I kept getting TLE

After spending some time investigating the issue I finally found the problem it was just one compiler flag

Accepted Solution

Spoiler

TLE Solution

Spoiler

My working code had:

#pragma GCC optimize("O3", "unroll-loops")

But my TLE code had:

#pragma GCC optimize("O3", "Ofast", "unroll-loops")

The only difference was Ofast

After removing it my solution passed

I didnt expect adding a optimization flag to make my code slower

Has anyone experienced something similar?

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

»
6 часов назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Bump!

»
5 часов назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Not every optimization flag makes the program faster. For example, if you use "unroll-all-loops" instead of "unroll-loops", it will run slower. In this case, "Ofast" is dangerous because it enables aggressive optimizations that violate language standards. Using "O3" is more safe and stable.