309117: CF1627B. Not Sitting

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Not Sitting

题意翻译

Rahul 和 Tina 在玩一个游戏。游戏在一个 $n\times m$ 的网格图上进行,记第 $r$ 行第 $c$ 列上的格子为 $(r,c)$。定义 $(a,b)$ 与 $(c,d)$ 之间的距离为 $\left|a-c\right|+\left|b-d\right|$。 游戏开始后,Tina 会选择恰好 $k$ 个格子,并将其涂成粉红色。涂完以后,Rahul 会选择任意一个**没有被涂成粉红色的格子**并在那个格子上坐下。此后,Tina 也会选择任意一个格子(**包括被涂成粉红色和没有被涂成粉红色的格子**)并在那个格子上坐下。Rahul 希望他和 Tina 之间的距离尽可能近,而 Tina 希望她和 Rahul 之间的距离尽可能远。于是,对于所有的 $k\in[0,n\times m-1]\cap\N^*$,Rahul 都想知道他和 Tina 之间的距离是多少。 数据范围: - $t$ 组数据,$1\leqslant t\leqslant 5\times 10^4$。 - $2\leqslant n\times m,\sum(n\times m)\leqslant 10^5$。 Translated by Eason_AC 2022.1.19

题目描述

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

说明

One possible sequence of choices for the first testcase where Tina has $ k=3 $ buckets of paints is as follows. Tina paints the seats at positions $ (1, 2) $ , $ (2, 2) $ , $ (3, 2) $ with pink paint. Rahul chooses the seat at $ (3, 1) $ after which Tina chooses to sit at $ (1, 3) $ . Therefore, the distance between Tina and Rahul is $ |3-1| + |1-3| = 4 $ , and we can prove that this is indeed the minimum possible distance under the given constraints. There may be other choices of seats which lead to the same answer as well. For $ k=0 $ in the first test case, Rahul can decide to sit at $ (2, 2) $ and Tina can decide to sit at $ (4, 3) $ so the distance between them would be $ |2 - 4| + |2 - 3| = 3 $ . Below are pictorial representations of the $ k=3 $ and $ k=0 $ cases for the first test case. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1627B/135a6759a6ba23b198694ead1674597ee527f081.png) A possible seating arrangement for $ k=3 $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1627B/f8d6f4f57279fb43f8c4bcfe0a1490483d3f4037.png) A possible seating arrangement for $ k=0 $ .

Input

题意翻译

Rahul 和 Tina 在玩一个游戏。游戏在一个 $n\times m$ 的网格图上进行,记第 $r$ 行第 $c$ 列上的格子为 $(r,c)$。定义 $(a,b)$ 与 $(c,d)$ 之间的距离为 $\left|a-c\right|+\left|b-d\right|$。 游戏开始后,Tina 会选择恰好 $k$ 个格子,并将其涂成粉红色。涂完以后,Rahul 会选择任意一个**没有被涂成粉红色的格子**并在那个格子上坐下。此后,Tina 也会选择任意一个格子(**包括被涂成粉红色和没有被涂成粉红色的格子**)并在那个格子上坐下。Rahul 希望他和 Tina 之间的距离尽可能近,而 Tina 希望她和 Rahul 之间的距离尽可能远。于是,对于所有的 $k\in[0,n\times m-1]\cap\N^*$,Rahul 都想知道他和 Tina 之间的距离是多少。 数据范围: - $t$ 组数据,$1\leqslant t\leqslant 5\times 10^4$。 - $2\leqslant n\times m,\sum(n\times m)\leqslant 10^5$。 Translated by Eason_AC 2022.1.19

加入题单

上一题 下一题 算法标签: