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

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

So I was golfing this problem, and I wanted to improve the line int c = t[v] = 1;, so I tried c = t[v] = 1;, with c defined earlier on in the same spot as a and b, but this didn't work. For the sample case, it gave the output 1 1 1 0 0 instead of 1 0 0 1 1.

I was wondering what that line actually does and if I can golf it more, so I found this question on quora, but even after reading that I still don't know why the other way isn't working. I use VSCode, so when I hover over the t[v] part, it says something to do with a reference to part of the bitset, so I'm thinking it's almost like a pointer to that index of the bitset, but that doesn't make sense because we're incrementing it, and you can't really increment a boolean value (which is basically what t[v] is..

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

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

It's a recursive function. If you try to use a global variable instead of a local variable, then it will be clobbered by nested calls.

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

    Oh that makes sense. Thanks!

    Also, thanks for the downvotes people, it looks like I'm nearing the most down-voted on codeforces!