Connection Status:
Competition Arena > GameOnABoard
SRM 583 · 2012-12-13 · by blue.boy · Graph Theory, Greedy, Search
Class Name: GameOnABoard
Return Type: int
Method Name: optimalChoice
Arg Types: (vector<string>)
Problem Statement

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 String[] cost. The j-th character of i-th element in cost (0-based index) denotes the cost of cell (i, j). A path between two distinct cells (x1, y1) and (x2, y2) is a sequence of cells (c0, c1, ..., ck) such that c0=(x1, y1), ck=(x2, y2) and for each i from 0 to k-1, cells ci and ci+1 have a common side. Cost of a path is the total cost of cells on this path.

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.
Examples
0)
{"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.

1)
{"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.

2)
{"011","011"}
Returns: 2
3)
{"00","11","00","10"}
Returns: 1
4)
{"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.

Coding Area

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

Submitting as anonymous