K for Knight

AMDAD_MBSTU Replay of MBSTU CSE Junio...
Limits 1s, 512 MB

Alice is a famous chess player. Her friend Bob wants to learn chess. So she gives him a task. The task is Alice will give him a chess board with nn rows and mm columns. There will be one very special knight in a cell (X,Y)(X,Y) on the board. Here, XX is the row number and YY is the column number. That knight is special because Alice decides how it will move. She will set two integers PP and QQ. The knight will be able to move PP squares by row (left or right) then QQ squares by column (up or down) or PP squares by column (up or down) then QQ squares by row (left or right).

Knight can not move outside of chessboard.

There are some cells in the board which are restricted, meaning knight can not move to those cells. Now he have to find the number of different cell that the knight can visit in a single move inside the board. Rows are numbered from 1 to nn and columns are numbered from 1 to mm and top-leftmost cell is (1,1)(1,1).

The picture shows all possible moves of a knight in a 5×55 \times 5 chess board from cell (X=3,Y=3)(X=3,Y=3) and (P=2,Q=1)(P=2,Q=1).

No cell is restricted in the above picture.


The first line of the input contains two integers nn and mm (1n,m100)(1 \leq n,m \leq 100). nn represents number of rows and mm represents number of columns of the chess board.

Second line of the input contains two integer XX and YY. (X,Y)(X,Y) represents the initial position of the Knight. Here XX is the row number and YY is the column number.

Third line contains (P,Q)(P,Q). Details about (P,Q)(P,Q) described in the statement.

Fourth line contains integer Z(0Z10)Z(0 \leq Z \leq 10),number of restricted cells.

The ithi-th of the next ZZ lines contains two integers Ci(1Cin)C_i(1 \leq C_i \leq n) and Di(1Dim)D_i (1 \leq D_i \leq m) — the position of the ithi-th restricted cell.

(1Xn)(1 \leq X \leq n) and (1Ym)(1 \leq Y \leq m).

(1P10)(1 \leq P \leq 10) and (1Q10)(1 \leq Q \leq10).

The initial position of the knight is not restricted.


Print the number of different cells the knight can visit in a single move.


5 5
3 2
2 2 
1 4
3 4
2 2
1 1 
1 3


Login to submit.


93% Solution Ratio
ToooonmoyEarliest, 3M ago
masud_ali58Fastest, 0.0s
emon.088977Lightest, 5.7 MB
MursaleenShortest, 595B
Toph uses cookies. By continuing you agree to our Cookie Policy.