Chess Board
InterviewTime limit1sMemory limit1024 MB
Given a 4 by 5 grid filled with 1 to 20, find the largest k such that each number from 1 to k is a knight move away from the previous one.
- Level
Easy3 of 10
- Topics
- Matrix, Simulation
- Solved
- No attempts yet
Problem
On October 13, 2012, students in grade 6 at the Hitar Petar Mathematical Competition in Gabrovo were given this problem.
Problem: Little Petarcho wants to tour every square of a board with consecutive knight moves, never returning to a square he has already visited. He found several solutions for a 3 x 4 board:

Find a solution for a 4 x 5 board:

Place the numbers 1, 2, ..., 20 in the squares so that a knight move from the square with 1 reaches the square with 2, from there the square with 3, and so on.
Help the jury check the solutions. Write a program board that reads a solution to Hitar Petar's problem and prints the number up to which the contestant got, starting from the square with 1 and following knight moves.
Input
Four lines are read from standard input, each containing five numbers. Each integer from 1 to 20 appears exactly once on the board.
Output
Print one line to standard output: the largest number the contestant reaches with knight moves, starting from the square with 1.