Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

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

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

I noticed a strange behavior when choosing the Microsoft Visual C++ 17 language. Structured binding is handled incorrectly.

Let's be concrete. I tried to solve that problem: https://codeforces.com/contest/1843/problem/E and noticed that exactly the same code leads to different decisions on different compilers. Namely, it was accepted when choosing G++17 (as well as G++20, Clang++20): https://codeforces.com/contest/1843/submission/210710990 and when choosing VC++17 it gave wrong answer on test 1: https://codeforces.com/contest/1843/submission/210711015 A small investigation showed that the problem was in the lines when I filled a vector of pairs using structured binding:

vector<pair<int, int>> segments(m);
for (auto& [l, r] : segments)
    cin >> l >> r;

^ not OK

As one can see from this submission: https://codeforces.com/contest/1843/submission/210711251 elements of the vector are not filled with input values for some reason, and remain the default zeroes. The problem was only with the vector of pairs. Vector of ints is initialized properly:

vector<int> xs(q);
for (auto& x : xs)
    cin >> x;

^ OK

I want to add that I couldn't reproduce the bug on my version of MSVC++ (Version 17.5.3). The problem was only with the compiler on the server. Is it some known bug of the MSVC++ compiler used on Codeforces? If it is, are there some more that are commonly known?

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

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

Yes, this is some bug

for (auto& pr : segments)
    cin >> pr.first >> pr.second;

works just fine

cout << _MSC_FULL_VER << endl; output 191125547 which corresponds to 15.4.5 version. I dont know in which version this bug was removed.

»
13 месяцев назад, # |
Rev. 3   Проголосовать: нравится +9 Проголосовать: не нравится

Yes, this is a bug in version 15.3. It was removed in version 15.5, which is after the version used by Codeforces.