TaroBalls
Rookie SRM 9 · 2022-01-21 · by Witaliy
Problem Statement
Cat Taro has a box with exactly R red balls and B blue balls inside. He and his friend decided to play the following game.
Players take alternate turns, Taro goes first. In each turn, the current player should take exactly one ball from the box. The only constraint is that the color of the ball he took must be different from the color of the previously taken ball (i.e., the one taken by the opponent in the immediately preceding turn). (Note that in the first turn Taro can take a ball of any color.) The player that cannot take a valid turn loses. Both players play optimally.
You are given the two
Constraints
- R and B will be between 1 and 1000, inclusive.
1 2 Returns: "Taro"
The best bet for Taro is to start with a blue ball. Then his friend will have to take a red ball, after which Taro will again take a blue one. There is no ball left for the friend. Thus, the winner is Taro.
1 1 Returns: "Friend"
Taro loses in this case.
4 7 Returns: "Taro"
999 1000 Returns: "Taro"
1000 999 Returns: "Taro"
Submissions are judged against all 158 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TaroBalls with a public method string getWinner(int R, int B) · 158 test cases · 2 s / 256 MB per case