Блог пользователя 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
  • Проголосовать: не нравится

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

Some days ago I completed all stages of the CodeCrafters "Build your own HTTP server" challenge in C++. My code was made to pass each stage of the challenge, but I took some extra time to refactor it into something that I could use in the future.

Check out my code on GitHub and feel free to share your feedback!

These are some of the issues I know exist or questions and would like to address:

  • I have some issues with posting files:

    • posting images, for example, doesn't work. I dont get the same file as the one I posted
    • I also just noticed that when posting text files it doesn't write the end lines
  • My Dispatcher takes a std::function<HttpResponse(HttpRequest&, std::vector<std::string>)> and then uses it to get a HttpResponse. But in some cases, (by now just when the response is built with .stream) I'm taking a reference to a stream that is built inside the function, when the function end it goes out of scope. Any elegant workaround for this? In my case I just declared the stream outside of my dispatcher build, but that's just a hack.

  • The base code given for the socket connection seems like it uses a C-style API. Is there any C++ way of using sockets?

Полный текст и комментарии »

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

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

In the last contest (Codeforces Round 933 (Div. 3)), while solving the problem 1941F - Рудольф и дисбаланс, I got WA on my first attempt. On debugging, I found this bit of code was problematic

const int INF = 1 << 30; // this is equal to 1073741824

I've always used this as my infinite value for integers, but it was not large enough in this case.

Note 1: Be sure your infinity is actually an upper bound for your problem

Well, I made INF large enough and submitted it again 250809384. WA. Can you spot the issue in my code? I was pretty sure that I didn't need to make every integer 64 bits so that the problem passed. But I did it and it passed.

Note 2: If doubtful, go ahead and make every int a long long int. It's ok for CP; avoid the unsuccessful submission penalty

The bug in my code was pointed out to me by Codeforces when I played a bit more after the contest 250815419. And it's so silly because I introduced that bug by rewriting the condition in a way I thought could be more efficient obscuring what I was trying to check. The gain in efficiency there would be that I could compute a0 + a1 only once and that the compiler probably makes 2 * fd really fast with a left shift. But why!? That would have had a negligible effect on the program as a whole.

As Donald Knuth said

premature optimization is the root of all evil...

In my case, it was not only premature but meaningless.

Note 3: Don't bother cutting edges unless it's actually useful and, more importantly, needed

I guess I'll be making posts like this whenever I do something that I regret in a contest. If you have any advice feel free to share it!

Полный текст и комментарии »

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

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

Just a piece of advice:

Read well the problem statements.

During Codeforces Round 932 (Div. 2), I was trying to solve a problem that was completely different from what the problem 1935D - Экзамен в ЦПМ was. I thought x and y had to be in the given set, and had no idea what magic to do to make it not at least n^2 (maybe that should have given me a hint that I was misreading).

Another piece of advice:

Go through the example test cases

If I had gone through the example I would have noticed.

(this is mostly a note to myself)

Полный текст и комментарии »

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

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

It has happened several times to me that I can't solve a problem in the contest but right after it finishes I come up with the solution.

I'm not worried about being unable to solve all the problems in Div.2 contest, not even some Div.3's, I'm aware I'm simply not good enough (yet?). But not being able to solve in-contest some problems that you can solve with a little more time hits differently.

It's another skill issue, just the fact that it takes me too much time to solve the other problems I manage during the contest.

Any advice on how to stop this from happening?

Полный текст и комментарии »

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

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

Codeforces has this option to "Offer to publish great rating rises", but when I hit the notification I don't see any social media share button or even one to share in a blog here in Codeforces.

Am I just not seeing it? What is the real purpose of it?

Полный текст и комментарии »

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

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

Can anybody tell me about C++ multimaps. As far as I know you can assign many values to a key but... how do I access to any of theese values?

Полный текст и комментарии »

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