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

Автор vok8, история, 6 лет назад, По-английски
  • Problem: XXOR

  • Submission-1: Link (Runtime Error)

  • Submission-2: Link (Accepted)

  • The difference between both the submissions is just the two cout<<""; statements, in the two "n" range for loops.

  • The cout<<""; statements are uncommented in Submission-2 and commented in Submission-1. And guess what, these statements convert a RE Submission to an AC Submission.

  • The code in Submission-1, for a Valid Random Input, runs finely in Codeforces' Custom Test, whereas it gives RE in AtCoder's Custom Invocation. (You may try, for more clarification and to find the reason!)

  • I found it weird! I am totally clueless about why this is happening. Can anyone please justify or explain, why is this happening?

  • Thank you!


UPD: It seems like, the cout<<""; statement(s) in the "n" range for loops, avoid (stop) the optimisation(s), which -OFast + "avx2" try to make, hence, converting the RE solution into an AC solution.

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

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

With pragmas:

Without pragmas:

It probably tried to optimize your loops.

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится +5 Проголосовать: не нравится

    Ohh, I get it! Thanks!

    But, if "pragmas" are the true reason behind this RE, why and how it would run finely on Codeforces' Custom Test?

    Also, the RE solution passes the 3 sample tests, and fails (gives RE) on other tests (except sample tests)! Seems Strange and Weird.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

It seems that Ofast + target("avx2") together causes Runtime Error. But using them separately gives AC.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

using O2 + target("avx2")

Why would you use pragma for O2? Any self-respecting judging platform would have O2 already enabled.

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

Consider the following code snipet

#include<bits/stdc++.h>
using namespace std;
int main() {
    cout << __builtin_cpu_supports("avx2");
}

When you run it through AtCoder's custom invocation, the output is 0. Which means AtCoder DOES NOT SUPPORT AVX2 and you shall never use it there. What happens is compiler optimizes your code using avx2 instructions but processor can't execute them. If you ever get AC with this pragma, it only means that compiler could not optimize your code using avx2 instructions.

However, it supports technologies like avx, sse ... sse4.2, popcnt. Most of the other stuff should work fine. But you should always verify technology support through __builtin_cpu_supports if you don't wanna get fucked.

UPD: The CPU model on which your code is executed seems to be different depending on how old the contest is. You can use avx2 as well as avx512 in the newer contests. I have no clue why did they do it this way.