Problem Statement
Lucyanna loves puzzles and she is always eager to invent new ones. She has recently invented a puzzle on a rectangular board.The board is divided into a grid of unit square cells. Each cell is painted either black or white. The rows are numbered starting from 0, from top to bottom. The columns are numbered starting from 0, from left to right.
The puzzle is played in a sequence of steps. In each step Lucyanna must choose exactly two distinct cells. Additionally, those two cells must lie either in the same row or in the same column. Let cell A be the chosen cell that is closer to the top left corner and let cell B be the other one. If both cells currently share the same color, paint cell B white. Otherwise, paint cell B black. After painting cell B using the previous rules, paint cell A white.
You are given the
- The
int[] answer encodes one possible sequence of steps that solves the puzzle. - The length of answer must be the same as the number of steps in your solution.
- The length of answer must be between 0 and 947, inclusive.
- If in step i (numbered starting from 0) you chose the cells (r1, c1) and (r2, c2), answer[i] should be equal to (r1 * 1000000 + c1 * 10000 + r2 * 100 + c2).
Definition
- Class:
- TransformBoardDiv2
- Method:
- getOperations
- Parameters:
- String[], String[]
- Returns:
- int[]
- Method signature:
- int[] getOperations(String[] start, String[] target)
- (be sure your method is public)
Notes
- Whenever there is a solution, there is a solution that has 947 or fewer steps.
- Any valid solution will be accepted. It is not necessary to minimize the number of steps.
Constraints
- N will be between 1 and 4, inclusive.
- M will be between 1 and 4, inclusive.
- start will contain exactly N elements.
- Each element of start will contain exactly M characters.
- target will contain exactly N elements.
- Each element of target will contain exactly M characters.
- No element of start and target will contain characters other than '#' and '.'.
Examples
{"#.",".."}
{"..",".#"}
Returns: {1, 10101 }
The example output describes a solution that consists of two steps. This is it: In the beginning: #. .. Step 0: we choose the cells (0,0) and (0,1). .# .. Step 1: we choose the cells (0,1) and (1,1). .. .#
{"..",".#"}
{"#.",".."}
Returns: {-1 }
{"#..#","#..."}
{"....","...#"}
Returns: {3, 1000103 }
{"#"}
{"#"}
Returns: { }
{"####","####","####","####"}
{"####","####","####","####"}
Returns: { }
{"#..#","...#",".##.","####"}
{"#..#","...#",".##.","###."}
Returns: {-1 }
{"####","####","####","###."}
{".###","####","####","####"}
Returns: {30303, 3 }
{"####","###.","##..","#..."}
{"...#","..##",".###","####"}
Returns: {30103, 3, 20202, 10002, 30203, 20003, 1010301, 1000101, 1020302, 1010102, 2030303, 2000203 }
{"#..",".#.","..."}
{"...","..#","#.."}
Returns: {200, 1010102 }
{"##.#","####","####","####"}
{"##.#",".###","####","##.#"}
Returns: {1020302, 1000102 }
{"###.","####","####","####"}
{".###","##.#","####","#.##"}
Returns: {3, 1020302, 3010302 }
{"####","####","####","##.#"}
{"#.#.","####","##.#","####"}
Returns: {10003, 2020302 }
{"#.##","####","####","####"}
{"#.##","#.##","####","####"}
Returns: {-1 }
{"####","####","####","##.#"}
{"####","###.",".##.","####"}
Returns: {2020302, 2000202, 1030203 }
{"#.##","####","#..#","####"}
{"....","#...","#.##","#..."}
Returns: {2, 30103, 1010103, 1020202, 1030303, 3010303, 3020303 }
{"#.##",".###","###.","##.#"}
{"....","#...",".##.","..#."}
Returns: {100, 20003, 1010102, 1030203, 2000203, 3010302, 3000303 }
{"#.##",".###","#.##","#.##"}
{"..#.",".#.#","....","#..."}
Returns: {3, 1020202, 2000202, 2020203, 3020303 }
{".###","##..","####","##.#"}
{"..##",".###",".#..","...."}
Returns: {20102, 10002, 1000103, 2000202, 2030303, 3000303, 3010303 }
{"##.#","####","#.##","##.."}
{"....","....","#...","###."}
Returns: {1, 30103, 1000103, 1010102, 2020302, 1030203 }
{"##..","###.","####","###."}
{"####","#...","#...","...."}
Returns: {-1 }
{"####","..##","####","##.."}
{".#..","..#.",".###","#..."}
Returns: {2, 30103, 2010301, 2000201 }
{"##.#","##.#","##.#",".###"}
{"....",".##.","...#","#..."}
Returns: {1, 1000102, 30103, 2000300, 2010301, 3020303 }
{".###","####","###.","#.##"}
{"###.",".#..",".#..","...."}
Returns: {-1 }
{"####",".#.#","##.#",".###"}
{"#...","##..","...#","..##"}
Returns: {-1 }
{"#.#",".#.","###","###"}
{"#..","..#","#..","#.#"}
Returns: {1010102, 20202, 2010202, 2020302, 3010302 }
{"#.#","##.",".##","###"}
{"#..",".##","#..","..#"}
Returns: {20102, 1000200, 2010202, 3000301 }
{"###","###","###","..."}
{"...",".#.","..#",".#."}
Returns: {1, 20102, 1000102, 1020202, 2000202, 2010301 }
{"#.", ".." }
{"..", ".#" }
Returns: {1, 10101 }
{"." }
{"." }
Returns: { }