Pragma optimization can cause TLE?

Revision en1, by M-I, 2026-11-27 13:13:11

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?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English M-I 2026-11-27 13:13:11 8147 Initial revision (published)