erray's blog

By erray, 5 weeks ago, In English

In today's contest, I submitted my F2 solution, it passed pretests and I was like, that's nice, nothing can go wrong, right? But in system tests, it failed, and I thought that's possible I'm dumb, looked at tests, and it was this

I thought it was about __lg(0), which I remembered it should've returned -1 and should've been totally fine, I wanted to test it and ran it on my computer and it used pretty much no memory, I knew Codeforces and my computers compiler can act differently, I said I've seen this one and ran the test on custom test, but it used pretty much no memory too, that had to be a mistake, I checked the compiler, the code and it was all same, is custom test judger different than system test one?

I thought that was weird but it got weirder, I was using c++20 before, switched to c++17 64 and the result was same, but on c++17 32, it got accepted and ran flawlessly on custom tests too, why is this happening?

Submissions and custom test results:

Contest submission: 132875579

C++17 64 submission: 132931778

C++17 submission: 132931841

C++20 custom test:

C++17 64 custom test:

(I'm sorry for everyone who got blind because of my grammar)

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

»
5 weeks ago, # |
Rev. 3   Vote: I like it +33 Vote: I do not like it

According to the C++ documentation, the behavior of the left-shift bitwise operator is undefined when the value of the right operand is negative or is greater or equal to the number of bits in the left operand. Note that the function __lg is not part of standard C++; it is just an internal library function. There is no guarantee that the return value of the function call __lg(0) is -1. Check the following C++20 accepted update to your code. 132946723

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +7 Vote: I do not like it

    I saw that too, thanks but my main point here is why custom test and problem testing judges give different results, shouldn't they need to be exactly the same? I mean nothing says that but when I'm using it I think that what I do here will result same when I submit my code.

    • »
      »
      »
      5 weeks ago, # ^ |
      Rev. 3   Vote: I like it +29 Vote: I do not like it

      I see your main point. A plausible explanation is that the custom-test judge and contest judge may be using different library implementations of the non-standard function __lg, even though both judges are running the same g++ program to compile the submitted code. MikeMirzayanov may let us know if both judges are using the same g++ program arguments or not.