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

Автор MaxWelll, история, 4 месяца назад, По-английски

I just got a WA verdict from the sample case in a problem that worked on my machine.

The issue was that I had some out-of-boundaries access in a vector. It happens. But the scary part is that it worked on my machine without any complaints.

I saw Mike's post about adding C++17 and it says and I quote:

The exact compilation command line is:

g++.exe -static -DONLINE_JUDGE -Wl,--stack=268435456 -O2 -std=c++17 -o %name%.exe %1 2>compilation.log`

First I tried copying the options but -Wl,--stack=268435456 doesn't work for me. I'm not sure what they do, options for the linker?

I'm using GNU/Linux (Ubuntu 24.04 to be more precise), and my compilation command is

g++ "$filename.cpp" -static -Wall -pedantic -O2 -std=c++17 -DEMWAVE -o "$filename"

I also tried some options that ChatGPT suggested but I could still run my program locally without any indication that something was wrong.

UPD

The WA verdict instead of Runtime Error indicates that the program didn't fail. Codeforces likely just ran a diagnostic after the WA verdict.

I'm not sure running a diagnostic before every submission is worthwhile.

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

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Maybe because "out-of-boundaries access in a vector" is UB. Everything can happen.

  • »
    »
    4 месяца назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    I know. Just wondering how to make my system more prone to behave badly in these cases.

    • »
      »
      »
      4 месяца назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      We can't really enforce what happens when the code reaches an undefined behavior, because we don't know what really happens then.

      You can start writing safer code. For example, out-of-range access for a vector can be resolved by using $$$v.at(i)$$$ instead of $$$v[i]$$$.