Connection Status:
Competition Arena > RealWithRooks
TCO19 Japan Regional · 2019-08-01 · by misof · Advanced Math, Math
Class Name: RealWithRooks
Return Type: String[]
Method Name: construct
Arg Types: (int, int, int)
Problem Statement

Problem Statement

You have an empty R x C chessboard and N colorless rooks. You are going to paint each rook either white or black. Then, you are going to place each rook onto some empty square of the chessboard. Your goal is to create a configuration that maximizes the number of attacking pairs of rooks.

Recall that two rooks attack each other if:

  • They have opposite colors.
  • They are in the same row or in the same column.
  • In that row or column, all squares that are between the two rooks are empty.

Return a String[] describing any one optimal placement of the rooks. The returned String[] must have R elements, each of those must have C characters, and each of those must be '.' (empty square), 'W' (white rook) or 'B' (black rook).

Constraints

  • R will be between 1 and 50, inclusive.
  • C will be between 1 and 50, inclusive.
  • N will be between 1 and R*C, inclusive.
Examples
0)
2
4
8
Returns: {"WBWB", "BWBW" }

In this test case you need to fill the whole board. There are still many ways to do so. You need to choose the colors in a way that maximizes the number of attacking pairs.

1)
5
5
9
Returns: {"W.B.W", ".....", "B.W.B", ".....", "W.B.W" }
2)
4
7
3
Returns: {".......", ".W...BW", ".......", "......." }
3)
5
6
27
Returns: {"..WBWB", ".WBWBW", "WBWBWB", "BWBWBW", "WBWBWB" }
4)
50
50
1
Returns: {"W.................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".................................................." }

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

Coding Area

Language: C++17 · define a public class RealWithRooks with a public method vector<string> construct(int R, int C, int N) · 205 test cases · 2 s / 256 MB per case

Submitting as anonymous