Sort 22 Discussions, By:
Please Login in order to post a comment
Please, explain me, what does it mean "....both players are moving optimally (playing to win and making no mistakes)."
The problem is not clear enough, not explained what "moving optimally" means, and it seems to be a crucial requirement.
If you think about the problem more carefully, only the number of elements that modulo 3=1 or 2 matters.
This leads to the following simple python solution
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
new_arr=[x%3 for x in arr]
print('Balsa') if (n_1&1)|(n_2&1) else print('Koca')
@afkaraoglu In your case there are following combinations:
B:7,18 K:8 Result:25-8=17 B wins
B:7,8 K:18 Result:15-18=-3 K wins
B:8,18 K:7 Result:26-7=19 B wins
B:8,7 K:18 Result:15-18=-3 K wins
B:18,7 K:8 Result:25-8=17, B wins
B:18,8 K:7 Result:26-7=19, B wins
Because both of two players will make no mistakes and try to win, Balsa will choose '18' as her first number and wins the game.
As a result, the output should be 'Balsa' in your test case.
I have a simpler solution.
First, map the original array to its remainder value (modulo 3).
Second, reduce the array to the XOR aggregation result.
Finally, decide which player wins based on the XOR result equals 0 or not.