№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Название |
---|
Your pragmas are the culprit. Remove them and you'll get AC. Submission: https://codeforces.me/contest/1580/submission/138986509
Lambda functions are not to blame here.
lol. I thought having those pragmas cant really hurt. So extended question, why is having pragmas with these lambda functions so slow?
I've narrowed the problem to
-ffinite-math-only -msse3
used together (disabling either one produces AC). Couldn't figure the rest yet. Don't understand why this matters to a program that doesn't use floating point numbers either.UPD: The two options together prevent GCC from inlining the
get
lambda for some reason.Here's the shortest reproducible example so far: https://godbolt.org/z/17b1951hY. The interesting part is that the
#include <cstdio>
line is required for this bug.It gets worse. https://godbolt.org/z/vhxfxKPjq
See, if I remove the definition of
fn
it inlines the lambda correctly, but if I add any (even empty) function, then it stops working. But only if this function is defined beforesolve
. Don't ask.If anyone's interested, I reported the (unconfirmed yet) bug here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
This is now fixed on trunk: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696#c6
Thanks for helping the community at large by reporting bugs like this!
I'm not so sure why, but
Ofast
is worse thanO3
in quite a few situations, so I avoid using it. As you mentioned in your comment, removing-ffinite-math-only
works (still don't know why), and it is turned on by default if you useOfast
, but not inO3
.Why a function was inlined in one context and why it wasn't in another context is a question that usually requires insight on the the choice of compiler optimizations in various contexts, which is a very complicated matter overall. In general, if you stick to
O3
and target few architectures, your code should not face such weird issues.I'm not sure about your particular scenario but in general lambda functions are a zero cost abstraction.
In fact, due to their narrower scope, the compiler can make stronger assumptions about their use, leading to better optimizations.