Chocolate and ㄱ나이트 Game (Bitter)
Time limit2sMemory limit1024 MB
Given a X by Y board and knight moves of (±x, ±y), find the maximum number of knights that can be placed so none can attack another.
- Level
Medium7 of 10
- Topics
- Math, Graph, Combinatorics
- Solved
- No attempts yet
Problem
Coco has a rectangular chocolate bar with width and height . The bar is divided into unit squares.
Coco wants to play the ㄱ나이트 game with this chocolate and several ㄱ나이트 pieces. A ㄱ나이트 is a variant of the chess knight. In one move, it can go to a square squares to the right or left and squares up or down from its current square. A ㄱ나이트 ignores the other pieces while it moves. If the destination is outside the chocolate, the piece cannot move there.
The ㄱ나이트 game is played by placing as many ㄱ나이트 pieces as possible on the chocolate under these rules:
- A square can hold at most one ㄱ나이트.
- If a ㄱ나이트 can move in one move to a square, that square must not hold another ㄱ나이트.
- The chocolate cannot be flipped or rotated.
Find the maximum number of ㄱ나이트 pieces that Coco can place on the chocolate.
Input
The first line contains the number of test cases .
Each test case is given on one line with four integers , , , and , separated by spaces.
Output
For each test case, print the maximum number of ㄱ나이트 pieces that can be placed on the chocolate, one per line.