题目描述
Due to the COVID pandemic, maintaining social distancing is of utmost importance. In this problem, you'd calculate how many days would it take to reach an apocalypse from an initial case if nobody maintains social distancing.
The Earth is flat (for this question) and it's dimensions are $R$ x $C$
The whole Earth is already divided into blocks and the virus can spread in all directions except diagonally. The virus from each newly infected person will spread in all directions in the next day, thus growing exponentially.
-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow.
- Next line contains $R$ and $C$ respectively separated by a space.
- Next line contains $x$ and $y$ respectively separated by a space, denoting the indices of the initial case in the world.
-----Output:-----
For each testcase, output in a single line an integer denoting the number of days after which everyone will be infected.
-----Constraints-----
- $1 \leq T \leq 10^4$
- $2 \leq R,C \leq 10^7$
- $0 \leq x,y \leq 10^7$
-----Subtasks-----
- 10 points : $1 \leq T \leq 5$ and $2 \leq R,C \leq 10$
- 20 points : $2 \leq R,C \leq 10^5$
- 70 points : Original constraints
-----Sample Input:-----
2
4 5
2 1
3 4
1 1
-----Sample Output:-----
5
3
-----EXPLANATION:-----
2nd test case:
Assuming, it's a small world of $3$ x $4$
0 is not infected. 1 is infected.
World indexing is like a 2D array:
(0,0) (0,1) (0,2) (0,3)
(1,0) (1,1) (1,2) (1,3)
(2,0) (2,1) (2,2) (2,3)
If this is the case on Day 0:
0 0 0 0
0 1 0 0
0 0 0 0
This will be the case on Day 1:
0 1 0 0
1 1 1 0
0 1 0 0
This will be the case on Day 2:
1 1 1 0
1 1 1 1
1 1 1 0
The End on Day 3:
1 1 1 1
1 1 1 1
1 1 1 1
Thus, answer will be 3
输入格式
见题面
输出格式
见题面