M-I's blog

By M-I, history, 35 hours ago, In English

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?

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

»
6 hours ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Bump!

»
5 hours ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.