#P6315. [COCI 2006/2007 #3] NPUZZLE

[COCI 2006/2007 #3] NPUZZLE

Problem Description

You are given a 4×44 \times 4 grid board. It contains the 1515 letters AOA \sim O and one . (which represents the empty cell). The standard positions of the letters are shown in the figure.

Now you are given a scrambled board. You need to compute the sum of the Manhattan distance from each letter’s current position to its standard position.

Input Format

There are 44 lines of input, and each line contains 44 characters describing the board.

Output Format

Output one line with one integer, which is the sum of the Manhattan distance from each letter’s current position to its standard position.

ABCD
EFGH
IJKL
M.NO 
2
.BCD
EAGH
IJFL
MNOK 
6

Hint

Explanation

This problem is translated from COCI2006-2007 CONTEST #3 T2 NPUZZLE

Translated by ChatGPT 5