hello everyone , why my submission in this problem accepted ? the time complexity of code in worst case is (10 ^ 12 ) , There are 17 attempts to hack my code but all are falid
the problem : 1238A - Вычитание простого
my submission : 62130511
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
hello everyone , why my submission in this problem accepted ? the time complexity of code in worst case is (10 ^ 12 ) , There are 17 attempts to hack my code but all are falid
the problem : 1238A - Вычитание простого
my submission : 62130511
Name |
---|
GNU C++ compiler is very smart :)
When it tried to compile your code, it saw:
1) if n<3, answer is NO.
2) if n>=3, then:
a) if n changed, answer is YES
b) if n hadn't changed, answer is YES too
So, in executable file your function "factorize" is never used.
How to see it?
At first, if you will write cout<<n<<endl in "factorize" function, your solution will immediately get TL.
At second, there is a site https://godbolt.org which shows you how your code looks like when it is already compiled.
Yep, it is very smart! Sometimes I cannot optimize my code in a complex code(that doesn't access arrays and doesn't do heavy operations). I leave it for the compiler to do its final job! ;)
thank you for explain this Wind_Eagle
I am not sure but I feel this is due to O2 optimization. I have tried your code on my local compiler and easily found a testcase that times it out. Codeforces uses very optimizing flags for best performance especially unroll loops which I feel is the reason for your fast code execution. You are not accessing any array which even fastens the code. All you are doing is simple operations and not heavy ones(except for the modulo in while loop which you don't check on a lot).
If I'm not mistaken this happens without -O2 too.
I guess. But somehow, it doesn't work with my local compiler. I have C++11 default flags on. I am not sure why it doesn't work. If you have a method to enable such on my local compiler, can you tell me it?
thank you for help
Ahmadsm2005
You're welcome!