Ritwin's blog

By Ritwin, history, 3 years ago, In English

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..

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

3 years ago, # |
  Vote: I like it +4 Vote: I do not like it

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.

  • »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Oh that makes sense. Thanks!

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