GameOnABoard
SRM 583 · 2012-12-13 · by blue.boy
Problem Statement
This problem statement contains superscripts and/or subscripts. These may not display properly outside the applet.
Alice and Bob are playing a game on a rectangular board. We use (i, j) to denote the j-th cell in the i-th row (0-based index). Each cell has a cost of either 0 or 1 and they are given by the
The game is played as follows: First Alice chooses a cell (x1,y1), then Bob chooses a cell (x2,y2) which is different from (x1, y1). Finally, they compute the value L: the minimum cost of a path between (x1,y1) and (x2,y2). Alice's goal is to minimize L, and Bob's goal is to maximize L. Compute and return the value L that will be achieved if both players play optimally.
Notes
- Two cells (x1, y1) and (x2, y2) have a common side if |x1-x2|+|y1-y2|=1.
Constraints
- cost will contain between 2 and 40 elements, inclusive.
- Each element of cost will be between 2 and 40 characters long, inclusive.
- Each element of cost will be of the same length.
- Each element of cost will consist of '0's and '1's only.
{"11",
"10"}
Returns: 2
Regardless of Alice's choice, Bob can always achieve L=2 by choosing the opposite corner. Sometimes he also has other optimal moves. For example, if Alice chooses (0,0), Bob can choose any of the other three cells to get L=2.
{"01",
"10"}
Returns: 1
Alice will not choose the cell (0,1), nor the cell (1,0). If she chooses one of those, Bob will choose the other one and L will be 2. Alice prefers the other option. If she chooses one of the cells (0,0) or (1,1), Bob can only achieve L=1.
{"011","011"}
Returns: 2
{"00","11","00","10"}
Returns: 1
{"00",
"11",
"11"}
Returns: 2
Submissions are judged against all 56 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GameOnABoard with a public method int optimalChoice(vector<string> cost) · 56 test cases · 2 s / 256 MB per case