CollectingRiders
SRM 382 · 2007-12-11 · by dkorduban
Problem Statement
A rider is a fantasy chess piece that can jump like a knight several times in a single move. (See notes for a description of how a knight jumps.) A rider that can perform a maximum of K jumps during a single move is denoted as a K-rider. For example, a 2-rider can jump once or twice during a single move, and a 1-rider is a traditional knight.
There are some riders of different types on a chessboard. You are given a
Notes
- A traditional knight has up to 8 moves from a square with coordinates (x,y) to squares (x+1,y+2), (x+1,y-2), (x+2,y+1), (x+2,y-1), (x-1,y+2), (x-1,y-2), (x-2,y+1), (x-2,y-1), and can not move outside the chessboard.
Constraints
- board will contain between 1 and 10 elements, inclusive.
- Each element of board will contain between 1 and 10 characters, inclusive.
- All elements of board will have the same length.
- board will contain only positive digits ('1'-'9') and '.' characters.
- board will contain at least one digit.
{"...1",
"....",
"2..."}
Returns: 2
The 2-rider can jump from (2,0) to (0,1) in the first move, and then from (0,1) to (2,2) to (0,3) in the second.
{"........",
".1......",
"........",
"....3...",
"........",
"........",
".7......",
"........"}
Returns: 2
In 2 moves, we can move all the pieces to the cell initially occupied by the 1-rider.
{"..",
"2.",
".."}
Returns: 0
No moves are necessary.
{".1....1."}
Returns: -1
{"9133632343",
"5286698232",
"8329333369",
"5425579782",
"4465864375",
"8192124686",
"3191624314",
"5198496853",
"1638163997",
"6457337215"}
Returns: 121
Kind of maximal test.
{"1..",
".1.",
"..."}
Returns: -1
impossible
{"1111111111",
"1111111111",
"1111111111",
"1111111111",
"1111111111",
"1111111111",
"1111111111",
"1111111111",
"1111111111",
"1111111111"}
Returns: 266
max answer
Submissions are judged against all 85 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CollectingRiders with a public method int minimalMoves(vector<string> board) · 85 test cases · 2 s / 256 MB per case