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

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

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.

Полный текст и комментарии »

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

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

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?

Полный текст и комментарии »

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