题库练习 Not Sitting
← 上一题 下一题 →

A14812 | Not Sitting

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Rahul and Tina are looking forward to starting their new year at college. As they enter their new classroom, they observe the seats of students are arranged in a $n \times m$ grid. The seat in row $r$ and column $c$ is denoted by $(r, c)$ , and the distance between two seats $(a,b)$ and $(c,d)$ is $|a-c| + |b-d|$ .

As the class president, Tina has access to exactly $k$ buckets of pink paint. The following process occurs.

- First, Tina chooses exactly $k$ seats in the classroom to paint with pink paint. One bucket of paint can paint exactly one seat.
- After Tina has painted $k$ seats in the previous step, Rahul chooses where he sits. He will not choose a seat that has been painted pink due to his hatred of the colour pink.
- After Rahul has chosen his seat, Tina chooses a seat for herself. She can choose any of the seats, painted or not, other than the one chosen by Rahul.

Rahul wants to choose a seat such that he sits as close to Tina as possible. However, Tina wants to sit as far away from Rahul as possible due to some complicated relationship history that we couldn't fit into the statement!

Now, Rahul wonders for $k = 0, 1, \dots, n \cdot m - 1$ , if Tina has $k$ buckets of paint, how close can Rahul sit to Tina, if both Rahul and Tina are aware of each other's intentions and they both act as strategically as possible? Please help satisfy Rahul's curiosity!

输入格式

The input consists of multiple test cases. The first line contains an integer $t$ ( $1 \leq t \leq 5 \cdot 10^4$ ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $n$ , $m$ ( $2 \leq n \cdot m \leq 10^5$ ) — the number of rows and columns of seats in the classroom.

The sum of $n \cdot m$ across all test cases does not exceed $10^5$ .

输出格式

For each test case, output $n \cdot m$ ordered integers — the distance between Rahul and Tina if both of them act optimally for every $k \in [0, n \cdot m - 1]$ .

输入输出样例

输入 #1
2
4 3
1 2
输出 #1
3 3 4 4 4 4 4 4 5 5 5 5 
1 1
C++ 编辑器
输入
输出