Connection Status:
Competition Arena > LeftToRightGame
2018 TCO Fun 3A · 2018-04-20 · by misof · Dynamic Programming, Greedy, Math
Class Name: LeftToRightGame
Return Type: String
Method Name: whoWins
Arg Types: (int, int)
Problem Statement

Problem Statement

Alice and Bob are playing a simple game. They take alternating turns writing the digits of a positive integer, from the left to the right. Alice starts. The number is not allowed to start with a zero, hence Alice must choose one of the digits 1 through 9 as her first move.

The game ends when the number has exactly length digits. Bob wins the game if that number is divisible by divisor. Alice wins in all other cases.

You are given the ints length and divisor. Return the name of the player who wins if both of them play the game optimally.

Constraints

  • length will be between 1 and 1000, inclusive.
  • divisor will be between 1 and 1000, inclusive.
Examples
0)
4
10
Returns: "Bob"

Alice and Bob are creating a 4-digit number. Bob wins if the number ends up being divisible by 10. As he is the one who will write down the last digit of the number, he has a very obvious winning strategy.

1)
3
1000
Returns: "Alice"

A positive three-digit integer will never be divisible by 1000. Alice wins this game regardless of how she and Bob play it.

2)
2
3
Returns: "Bob"
3)
147
47
Returns: "Alice"
4)
7
3
Returns: "Alice"

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

Coding Area

Language: C++17 · define a public class LeftToRightGame with a public method string whoWins(int length, int divisor) · 142 test cases · 2 s / 256 MB per case

Submitting as anonymous