Sea Battle
InterviewTime limit2sMemory limit1024 MB
Given an n by m board and k ships, print INCORRECT if any ships overlap or touch, otherwise count the cells where a new 1x1 ship can go without touching any ship.
- Level
Easy3 of 10
- Topics
- Matrix, Implementation
- Solved
- No attempts yet
Statement
Little Yan is writing an artificial intelligence for a game of Battleship.
Battleship is a two-player game. Each player has a rectangular grid of size and places several ships on it. Each ship is a horizontal rectangle of height 1 or a vertical rectangle of width 1, and it covers several cells in full. Ships must not share any points, even on the border.

At some point in the game, one module of Yan's program must count the number of possible positions for an enemy ship of size . At that moment, the positions of some other ships are already known. The module must check whether the opponent broke the placement rules. If not, it must count how many positions are available for one more ship.
Help Yan write this part of the program.
Input
The first line contains three integers , , and (; ), the board size and the number of known enemy ships.
Each of the next lines contains four integers , , , (; ), the coordinates of the top-left and bottom-right cells of a ship.
If a ship is vertical, then . If it is horizontal, then .
Output
If two ships share a point (the opponent broke the rules), print the single word INCORRECT. Otherwise, print a single integer, the number of possible positions for one more enemy ship of size .
Hint
The dots in the picture mark the possible positions of the enemy ship in the first example.