backo's blog

By backo, history, 9 years ago, In English

Hello!

Can anyone tell me how to update my g++ compiler for C++ to the exact version that's used by the judge on codeforces? I'm using Windows 7 and I'm not using any IDE (i compile from the commandline). Currently I have g++ version 4.8.1 and I can't find where to download 5.1.0. Tried to download minGW but it keeps installing the old 4.8.1 version.

Before, I didn't care that the compiler versions didn't match, but this last competition (330 div 2) got me really pissed off. I figured out the solution to the B problem, but I kept getting WA on pretests. After the contest, I tried submitting the solution and I saw that my solution was giving the wrong answer on their machine, while I was getting the corrent answer on my PC. After some tweaking I figured it was the pow() function that was causing the trouble. After i manually calculated 10^k instead of calling pow(10,k), I got accepted.

This thing with different compiler versions is REALLY annoying and unpredictable because god knows how many more functions like pow() work differently on different compiler versions.

Also, what are the compiler options (like -Wall) used by the judge?

Thanks

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

| Write comment?
»
9 years ago, # |
  Vote: I like it +30 Vote: I do not like it

If you are using Windows, you can visit PBOX, install it (as written on the home page). After it pbox install mingw-tdm-gcc will install exactly the same version of g++ as Codeforces uses. Also you can use it to install almost all software with exact version as Codeforces judging machines use.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks! That's actually very simple. I did as you said. Now when I write "pbox list-installed" I get version 5.1.0 but when i try "g++ --version" it still says 4.8.1. Am I doing something wrong?

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      You can try to restart cmd.exe session + remove your previous installation. You can execute pbox install tools to install many useful commandline tools (+ restart cmd) and run `where g++' to find the complete path to your old g++.

      • »
        »
        »
        »
        9 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I figured it out. I edited the "Path" environment variable and removed the old C:\MinGW. There was probably a collision with the old g++.exe and it always chose the old one. Now I get the 5.1.0 version when i write "g++" in the command line. Thanks alot!

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thx, Mike.

»
9 years ago, # |
  Vote: I like it +8 Vote: I do not like it

This thing with different compiler versions is REALLY annoying and unpredictable because god knows how many more functions like pow() work differently on different compiler versions.

in your case, compiler versions are irrelevant. Codeforces servers are much more sensitive to memory safety than your PC because they're under heavy workload. Write correct code (for example, add eps when dealing with floats) if you want to avoid this kind of errors.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    So I was thinking, pow(10,3) probably returned 999.99999 and when I saved it to a long long, it gave me 999. I should have rounded it first. I think this was the whole problem. Still, I think updating the compiler is important