maroonrk's blog

By maroonrk, history, 6 weeks ago, In English

What if your solution got TLE due to denormal numbers? Would you add if(val<eps)val=0 everywhere? Today I found a simpler fix: let's include #include <xmmintrin.h> and insert _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); at the beginning of the main function.

Example Problem

TLE Submission

AC Submission

I confirmed this magic works on AtCoder, Codechef, Yandex, and, of course, on Codeforces.

Since it's written on the Wikipedia page, I won't be surprised if this is a well-known trick in some countries. However, I and my friends haven't heard of this, so it must be worth sharing.

Note that I know nothing about what exactly this snippet does, and I'm happy to hear from computer experts what the possible defects it has if such exist.

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

»
6 weeks ago, # |
Rev. 2   Vote: I like it +67 Vote: I do not like it

It might be a little hard to remember, but you can actually manipulate mxcsr register yourself as below without including any additional headers to achieve the same effect.

int main() {
  __builtin_ia32_ldmxcsr(__builtin_ia32_stmxcsr() | 0x8000);
  return 0;
}
»
6 weeks ago, # |
  Vote: I like it -95 Vote: I do not like it

great content learnt a new thing

»
6 weeks ago, # |
  Vote: I like it -89 Vote: I do not like it

so learn silently don't brag here