Max-Queen
Time limit2sMemory limit1024 MB
Place queens on an n by m board to maximize the number of attacking pairs, where a queen blocked by another queen does not attack past it.
- Level
Medium5 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
There is a chessboard with rows and columns. You want to place at least queen on this board.
You can place at most queen in each cell. In other words, each cell either holds one queen or holds no queen.
Two queens can attack each other when they are in the same row, the same column, or the same diagonal, and no queen stands between them. When queen and queen can attack each other, the ordered pair is called an attacking pair. The attacking pairs and are treated as the same.
For example, placing queens as shown below gives distinct attacking pairs.

Write a program that finds the maximum possible number of distinct attacking pairs.
Input
The first line contains the number of rows and the number of columns , separated by a space. ()
Output
Print the answer to the problem on one line.
Hint
The answer can exceed the maximum value of a 32-bit integer. Use the following types to store the value.
- C/C++:
long long - Java:
long - Python:
int(no special handling is needed.) - Other languages: refer to the language reference.