Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

Tomg's blog

By Tomg, history, 3 years ago, In English

In Java, why is it that the code a^=b^=a^=b does not swap the values of a and b, while in C++, such code works? For example if a=1, and b=5, in Java, after doing a^=b^=a^=b, a=0, b=1.

Full text and comments »

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

By Tomg, 4 years ago, In English

I was trying to figure out why there is a difference in verdict in these two solutions for 1354F - Summoning Minions (summoning minions):

Solution that gives WA on test case 32 of test 2: https://pastebin.com/EzbSDw3Z

AC Solution: https://pastebin.com/DjFkheFs

The only difference between these two solutions is that when deciding whether to include one of the minions, in WA solution, I try to find max(dp[i-1][j]+minion[i].b*(k-1), dp[i-1][j-1]+minion[i].a+minion[i].b*(j-1)), which should give the actual value of the dp at that state.

On the other hand, the AC solution finds max(dp[i-1][j], dp[i-1][j-1]+minion[i].a-minion[i].b*(k-j)). I expected both methods to produce the same result, and tried to find an instance where the methods would produce different results, but I could not.

Can anyone explain why the first method causes WA?

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it