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

Автор maroonrk, история, 2 года назад, По-английски

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.

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

»
2 года назад, # |
Rev. 2   Проголосовать: нравится +67 Проголосовать: не нравится

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;
}
»
2 года назад, # |
  Проголосовать: нравится -89 Проголосовать: не нравится

so learn silently don't brag here