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

Блог пользователя AB.devil

Автор AB.devil, история, 4 года назад, По-английски

Why are the methods Vector.empty() and Vector.size() == 0 not working. I get the following error- Probably, the solution is executed with error 'not valid value for bool' on the line 34. Here are the submission links - 1. https://codeforces.com/contest/744/submission/90258791 2. https://codeforces.com/contest/744/submission/90257488 Please help!

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

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

Replace bool[] arrays with vector

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

I believe the error is thrown by the "isGov" array, in which you have possibly not assigned values to all elements, but later attempt to access all of them. But since in arrays, the initial value is random, it is not recognized as a boolean value and causes an error.

I would suggest either using a vector or setting all values to false initially.

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

In which order is this evaluated? if (v[i].size() == 0 && !isGov[i])

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

The problem is not that, I think using vector instead of bool [] will work, or you can use memset and initialize all values of isGov as false at the beginning.

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

In your code isGov is uninitialized

bool isGov[n+1];

should be replaced with

bool isGov[n+1]{};

You should use a vector though as others have suggested.

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

    Does the latter guarantee that everything is 0? Same of an array of ints?

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

      Yes, the latter guarantees everything is zero. This feature for VLAs is a G++ extension, however. (variable-length arrays in C++ are also a G++ extension). For non-VLAs, array brace initialization is part of C++. (Variable-length arrays are arrays with a dynamic size)