Connection Status:
Competition Arena > TakeStones
Rookie SRM 3 · 2021-03-05 · by erinn · Dynamic Programming, Math
Class Name: TakeStones
Return Type: String
Method Name: result
Arg Types: (int, int)
Problem Statement

Problem Statement

You are playing a game where you and another player alternately take turns taking stones from a single central pile of stones.

Initially, the pile contains stonePile stones.

You are the first player to make a move. On each turn, the active player must take at least one stone and at most maxStones stones from the central pile.

Assume that both you and the other player play the game optimally. Return "WIN" if you will win the game or "LOSE" if you will lose the game.

Notes

  • The return value is case-sensitive: the "WIN" and "LOSE" must be in uppercase.

Constraints

  • stonePile will be between 1 and 100, inclusive.
  • maxStones will be between 1 and 100, inclusive.
Examples
0)
5
3
Returns: "WIN"

The central pile starts with 5 stones. During each turn the active player may remove between 1 and 3 stones, inclusive. You can win the game regardless of how well your opponent plays. If you start by taking one stone, the other player is left with four stones in the central pile. Regardless of how many they take (1, 2, or 3), in your second turn you can always take everything they left in the central pile and win.

1)
4
3
Returns: "LOSE"

Here, it's the opposite situation. Regardless how many you take, the opponent will be able to take the rest and win.

2)
7
5
Returns: "WIN"
3)
30
8
Returns: "WIN"
4)
100
99
Returns: "LOSE"
5)
7
47
Returns: "WIN"

Your winning strategy in this game is simple: on your first turn, take all seven stones and win.

Submissions are judged against all 23 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TakeStones with a public method string result(int stonePile, int maxStones) · 23 test cases · 2 s / 256 MB per case

Submitting as anonymous