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

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

Hi, while submitting 1535F - String Distance for the previous educational round I did observe a strange behaviour. I submitted the absolutely same code several times:

image

As you can see, submitting with C++17 was AC every single time. Submitting with C++17 (64bit) lead to timeouts on different testcases, like 18, 27 or 32 but also to several AC with all testcases 18,27,32 only needing <300ms in 64bit. I read my code about 20 times now checking for out of bounds errors or stupid mistakes. I have no random numbers generated. I also did several tests by generating a big number of random testcases with both 64bit and 32bit locally, but I couldn't reproduce this behaviour. I got consistent times all around. Now I'm clueless and want to ask whether someone has an idea why this happens.

Some details about the code

Thank you for your help!

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

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +37 Проголосовать: не нравится

Maybe there are different types of testing machines and depending on which one gets assigned to test your submissions, you get different times. If you can't reproduce it locally, it's mainly a question for CF staff.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +8 Проголосовать: не нравится
long long nAll;
vector<pair<string, string>> in(nAll);

This is weird thing to have in global space. But it is not technically wrong.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +100 Проголосовать: не нравится

I did some more digging into this, and I got ahold of the test cases. The test cases are generated in packs of 9, which explains why there is a pattern of TLE at 18, 27, 36.

I tried to run your program locally, both with sanitizers and debug flags. Locally everything simply works, no issues at all. It runs pretty quickly too, not even close to TLE. So my best guess is that something is wrong on CF's side.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +62 Проголосовать: не нравится

One observation. If we remove reference & from this loop: for(vector<string>& strs : strGroups), the code never gets TLE. Now it looks more like UB, but I wasn't able to find something illegal.

»
5 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +55 Проголосовать: не нравится

An update on this issue. I've tried two additional things.

  1. I tested creating a mashup on CF where I manually increased the TL. It seems like the 64 bit C++ program randomly either gets AC in 0.2 s or 11 s. It takes consistently either 0.2 s or 11 s, and nothing in between.

  2. On my windows laptop (which I believe to be similar spec compared to CF servers), I downloaded pbox.me (package manager by Mike) and installed the exact version of the 64 bit C++ compiler that CF uses. I've also gotten a hold of all the problematic test cases. Even doing all of this, I have not been able to recreate the issue locally.

I have no clue what could explain the program randomly running ~50 times slower. I've read the code, I've ran sanitizers. As far as I can tell there is no UB going on.