Variant Chess: Dabbaba
InterviewTime limit2sMemory limit1024 MB
Count the distinct empty squares on an N by N board that at least one Dabbaba can reach by moving exactly 2 squares up, down, left, or right.
- Level
Easy3 of 10
- Topics
- Hash map, Implementation
- Solved
- No attempts yet
Problem
Eundong likes playing with chess pieces more than playing chess itself. Today he wants to play with the Dabbaba, one of the variant chess pieces, on a board.

Dabbaba move
A Dabbaba moves 2 squares up, down, left, or right. Like a knight, it can jump over other pieces. However, it cannot move outside the board, and it cannot move to a square occupied by another piece.
While Eundong was playing, Beusil accidentally scattered Dabbabas across the board. Looking at the board, Eundong thought for a moment and wondered how many squares a Dabbaba on the board can reach in one move.
Given the board size and the number of Dabbabas , count all squares that a Dabbaba can reach in one move. If several moves reach the same square, count it only once.
Input
The first line contains the board size and the number of Dabbabas , separated by a space.
The second through -th lines each contain the position of a Dabbaba, separated by a space.
No two pieces are on the same square.
Output
Print the number of squares that a Dabbaba on the board can reach in one move.