AmmarDab3an's blog

By AmmarDab3an, 9 months ago, In English

I don't know why, but using std::array causes RTE in official contests.

In a local contest, there was a problem that I solved using matrices, and because I was used to using Array<> to store the values of the matrices, I faced weird run time errors if I compiled my solution using the Test button on the PC2 on my machine, or if I submitted my solution to the judge. Not just in the locals, but also in the recent 2023 ACPC competition there was a similar problem and some teams that didn't know of the problem faced the same issue which caused them to lose most of the contest's time trying to figure things out without any luck.

It's also a good idea to use the Test button on the PC2 before submitting any problem to catch such errors or to check if the problem was solved.

If anyone know why such a behavior is happening or how to use Array<> without getting an RTE, please share the solution.

Full text and comments »

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

By AmmarDab3an, history, 11 months ago, In English

ai generated markdown:

Here are the steps to speed up C++ compilation time by precompiling the "bits/stdc++.h" header on a Windows machine and modifying CodeBlocks' settings to use them:

  1. Delete the Mingw compiler from CodeBlocks and remove Mingw from PATH if it is present.

  2. Download the latest version of msys2.

  3. Open the MSYS2 shell from the start menu and execute the following commands:

  • Update the package database by running pacman -Sy pacman.
  • Update the package database and core system packages with pacman -Syu.
  • Update the remaining packages with pacman -Su.
  • For a 32-bit system, install the 32-bit toolchain by running pacman -S mingw-w64-i686-toolchain. For a 64-bit system, install the 64-bit toolchain with pacman -S mingw-w64-x86_64-toolchain.
  1. Open the Command Prompt as an administrator, navigate to the C: drive, and execute mklink /D MingGW C:\msys64\mingw64.

  2. Edit the system environment variables by going to "Environment Variables," double-clicking on PATH, and adding C:\MinGW\bin as a new entry.

  3. Open the Command Prompt and navigate to the path C:\MinGW\include\c++\13.2.0\x86_64-w64-mingw32\bits.

  4. Execute the following 8 commands in the Command Prompt:

  • g++ -fexceptions -g -std=c++17 stdc++.h -O0 -o stdc++_17_O0.gch
  • g++ -fexceptions -g -std=c++17 stdc++.h -O1 -o stdc++_17_O1.gch
  • g++ -fexceptions -g -std=c++17 stdc++.h -O2 -o stdc++_17_O2.gch
  • g++ -fexceptions -g -std=c++17 stdc++.h -O3 -o stdc++_17_O3.gch
  • g++ -fexceptions -g -std=c++20 stdc++.h -O0 -o stdc++_20_O0.gch
  • g++ -fexceptions -g -std=c++20 stdc++.h -O1 -o stdc++_20_O1.gch
  • g++ -fexceptions -g -std=c++20 stdc++.h -O2 -o stdc++_20_O2.gch
  • g++ -fexceptions -g -std=c++20 stdc++.h -O3 -o stdc++_20_O3.gch
  1. Create a new folder named stdc++.h.gch in C:\MinGW\include\c++\13.2.0\x86_64-w64-mingw32\bits, and move all the previously generated files into it.

  2. Open CodeBlocks and navigate to "Compiler Settings," "Global Compiler Settings," "ToolChain Executables." Set the compiler's installation directory to C:\msys64\mingw64.

  3. In CodeBlocks, go to "Compiler Settings," "Global Compiler Settings," "Compiler Flags," and check the box for [-O2] under "Optimization."

  4. In CodeBlocks, go to "Compiler Settings," "Global Compiler Settings," "Other compiler options," and add -std=c++17 or -std=c++20 ( important ).

  5. In CodeBlocks, go to "Debugger Settings Default," "Executable path," and paste C:\msys64\mingw64\bingdb.exe.

you should have something like this:

Full text and comments »

Tags c++
  • Vote: I like it
  • +39
  • Vote: I do not like it

By AmmarDab3an, history, 2 years ago, In English

Since I started CP I created a repo to collect all my solutions and CP related materials, feel free to use any of them:

https://github.com/ammardab3an/acm

Full text and comments »

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