AnotherTokenGame
TCO 2019 Final · 2019-11-14 · by lg5293
Problem Statement
Lucas and Greg are playing a board game.
The board consists of n spaces in a line.
Initially, each space is either empty (denoted '.'), or contains a single lime-colored token (denoted 'L').
All lime-colored tokens are owned by Lucas.
This state of the board is described by the input you are given: the
Next, Greg will choose a non-negative integer k not exceeding the number of empty spaces. He will then receive k gray tokens (denoted 'G') which he can distribute among k empty spaces of the board. Each empty space can hold at most one token. All gray tokens are owned by Greg.
Once Greg finishes placing his gray tokens, the actual game starts. In the game Lucas and Greg take alternating turns, with Lucas going first. In each turn of the game the current player chooses a token of their color and moves it either one space to the left or one space to the right. (The destination space must be empty.) If there are no available moves, the current player loses.
In some cases the game can go on indefinitely. Greg would like to know the minimum value of k such that he can guarantee a win, assuming he places his k tokens optimally and then plays optimally. Return this value of k.
Notes
- Note that Greg can guarantee a win by placing his tokens onto all empty spaces on the board, so the answer is always correctly defined.
Constraints
- s will contain between 1 and 2,500 characters, inclusive.
- Each character of s will be either 'L' or '.'.
"....." Returns: 0
Lucas has no tokens, so loses on the first turn no matter how many tokens Greg decides to place.
"..L....." Returns: 1
Greg can place his token on the second square. Lucas is forced to move his token to the right, and Greg can keep following.
"LL....L..L." Returns: 3
One possible way is for Greg to place his tokens as follows "LLG...LG.LG"
".L.L." Returns: 2
".L.LL." Returns: 3
Submissions are judged against all 139 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AnotherTokenGame with a public method int getSmallest(string s) · 139 test cases · 2 s / 256 MB per case