We have $$$n$$$ squares, $$$s_1, s_2, \dots, s_n$$$, on a 2D plane. Now, we want to draw a square $$$S$$$ such that for each of the existing squares, the intersection with $$$S$$$ is also a square with nonzero area.
Formally, we want to find a new square $$$S$$$ such that for each $$$i \in \{1, 2, \dots, n\}$$$, the intersection $$$S \cap s_i$$$ is also a square with nonzero area.
Print out any valid square $$$S$$$.
The first line contains $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$), the number of squares laid out.
Each of the next $$$n$$$ lines describes a square using four integers $$$x_1, y_1, x_2, y_2$$$, where $$$(x_1, y_1)$$$ is the lower-left corner and $$$(x_2, y_2)$$$ is the upper-right corner. It is guaranteed that $$$x_1 \lt x_2$$$, $$$y_1 \lt y_2$$$, and that the shape described is an axis-aligned square. All coordinates lie within the range $$$[-10^9, 10^9]$$$.
Output the square $$$S$$$ as four integers $$$x_1, y_1, x_2, y_2$$$, denoting its lower-left and upper-right corners. It must satisfy $$$x_1 \lt x_2$$$ and $$$y_1 \lt y_2$$$, and all coordinates must lie within the range $$$[-10^9, 10^9]$$$. The square must be axis-aligned.
3 2 3 4 5 7 3 10 6 8 1 12 5
3 4 9 10
1 1 1 2 2
1 1 2 2
Below is an illustration of the sample test case, where the blue squares are the ones given in the input and the red square is our output.
—
Problem Idea: Alex_C
Problem Preparation: eysbutno
Occurrences: Novice A / Advanced A
Unable to avoid the AI takeover, Bocchi has recently started studying neural networks! She has learned a special type of neural network that can be modeled as a specific type of graph.
The structure of this graph is special: it consists of $$$n + 2$$$ nodes, each with some value $$$v_i$$$. Bocchi also notices that all values from $$$0$$$ to $$$n + 1$$$ are present. The graph has a starting node, $$$d$$$ layers of nodes, and an ending node*. Nodes within each layer aren't connected, but each node in layer $$$i$$$ is connected to every node in layer $$$i + 1$$$ with a directed edge, with the starting node being connected to every node in layer $$$1$$$ and every node in layer $$$d$$$ being connected to the ending node. The starting node's value is always $$$0$$$, while the ending node's value is always $$$n + 1.$$$
After studying the neural network for some time, she deems the efficiency of a certain path from the starting node to the ending node to be the $$$\text{MEX}$$$** of the values on the path.
For example, suppose that there are two layers, the first consisting of nodes of values 4 and 1, and the second consisting of nodes of values 2 and 3. The starting node is 0 and the ending node is 5.
Perusing all of the options:
To see how well her neural network works, she gives her neural network an evaluation score. Specifically, the evaluation score is equal to the maximum efficiency over all paths from starting node to ending node. In the example neural network above, the path with the highest efficiency is the path $$$0\rightarrow1\rightarrow2\rightarrow5,$$$ so the evaluation score of the neural network is $$$3.$$$
After spending all day building her neural network, she is too tired to evaluate it. She now gives you her neural network and asks you to find the evaluation score of it!
Notes:
* For this problem, the starting and ending nodes do not count as layers.
** The $$$\text{MEX}$$$, or minimal excluded, of a sequence is the smallest non-negative integer not present in that sequence.
The first line contains two positive integers: $$$n$$$ $$$(1 \le n \le 5 \cdot 10^5)$$$, the total number of nodes in the layers (that is, excluding the starting and ending nodes), and $$$d$$$ $$$(1 \le d \le n)$$$, the number of layers.
There are then $$$d$$$ lines: the first number contains $$$m$$$, the number of nodes in the layer, followed by $$$m$$$ integers, denoting the value of each node.
It is guaranteed that all values from $$$0$$$ to $$$n + 1$$$ are present.
Note: The starting and ending nodes are not included in the input.
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-5$$$ satisfy $$$n \leq 10$$$.
Tests $$$6-10$$$ satisfy $$$n \leq 100$$$.
Tests $$$11-15$$$ satisfy $$$n \leq 1000$$$.
Tests $$$16-20$$$ satisfy no additional constraints.
Output a single integer—the evaluation score of the neural network.
4 22 4 12 2 3
3
Problem Idea: otat
Problem Preparation: ThatRowletOwlet
Occurrences: Novice B
melting?
You are given a tree with $$$n$$$ nodes, rooted at node $$$1$$$. The $$$i$$$-th node has a strength of $$$w_i$$$, meaning it can withstand a total of $$$w_i$$$ kgs of snow in its subtree. If a node has more than $$$w_i$$$ kgs of snow in its subtree, it is too heavy, and it will break.
At the end of every day, snow falls on every node. That is, $$$a_i$$$ kgs of snow fall on the $$$i$$$-th node. The snow falls instantaneously.
You may reinforce up to $$$k$$$ nodes, making them unbreakable. You wish to strengthen the tree such that the maximum possible amount of snow will gather on the tree before it breaks. The tree breaks once any of its nodes break. Snow that falls on the day that it breaks does not count.
For each $$$k = 0, 1, \dots, n-1,$$$ output the maximum weight of snow that the tree can gather.
The first line contains one integer $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^5)$$$ — the number of nodes in the tree.
The second line contains $$$n$$$ integers $$$w_i$$$ $$$(1 \leq w_i \leq 5 \times 10^6)$$$ — the strength of the $$$i$$$'th node.
The third line contains $$$n$$$ integers $$$a_i$$$ $$$(1 \leq a_i \leq 5 \times 10^6)$$$ — the amount of snow that falls on the $$$i$$$'th node.
Each of the next $$$n-1$$$ lines contains two integers $$$u_j, v_j$$$ $$$(1 \leq u_j, v_j \leq n)$$$ – the nodes of the $$$j$$$'th edge. It is given that the edges form a tree.
—
Tests in subtasks are numbered from $$$1-20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-20$$$ satisfy no additional constraints.
For each value of $$$k$$$, print the integer $$$a$$$ — the amount of snow that will gather on the tree.
330 4 55 1 31 21 3
9 27 36
5100 50 2 3 41 1 1 2 31 21 32 42 5
8 8 16 64 96
Problem Idea: jay_jayjay
Problem Preparation: iframe
Occurrences: Novice C
Alice and Bob are playing a game on an array $$$A$$$ consisting of $$$n$$$ positive integers. Alice picks some $$$i$$$ and sets $$$A[i]$$$ to $$$A[i]$$$ $$$|$$$ $$$x$$$. Then, Bob picks some $$$j$$$ and sets $$$A[j]$$$ to $$$A[j]$$$ $$$\&$$$ $$$y$$$. Note that each player only plays one turn. The score of the game is equal to the sum of $$$A$$$.
Alice wants to minimize the score while Bob wants to maximize the score. Find the score of the game if both players play optimally.
The first line of input contains the number of testcases $$$t$$$ $$$(1 \le t \le 10^3)$$$. The description of the test cases follows.
The first line of each test case contains three positive integers $$$n$$$, $$$x$$$, and $$$y$$$ $$$(1 \le n \le 10^5$$$, $$$ 1 \le x, y \le 10^9)$$$ — the size of the array $$$A$$$ and the two integers being applied to the array.
The second line of each test case contains $$$n$$$ positive integers $$$A_1, A_2, \ldots, A_n$$$ $$$(1 \le A_i \le 10^9)$$$.
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-4$$$ satisfy the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$.
Tests $$$5-20$$$ satisfy the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output the score of the game if both players play optimally.
54 5 21 4 3 65 6 32 5 7 1 43 3 42 3 55 536870912 268435456536870912 268435456 800000000 900000000 1234567895 2 61 3 2 4 5
14 19 9 2628763157 15
In the first test case, Alice can choose $$$i = 1$$$ so that $$$A[1] = 4|5 = 5$$$ and Bob can choose $$$j = 0$$$ so that $$$A[0] = 1\&2 = 0$$$. The resulting array $$$A = \{0, 5, 3, 6\}$$$ which leads to the optimal sum of $$$14$$$.
In the second test case, an optimal solution is Alice can choose $$$i = 2$$$ so that $$$A[2] = 7|6 = 7$$$ and Bob can choose $$$j = 0$$$ so that $$$A[0] = 2\&3 = 2$$$. The resulting array $$$A = \{2, 5, 7, 1, 4\}$$$ which leads to the optimal sum of $$$19$$$.
—
Problem Idea: HaccerKat
Problem Preparation: feining_for_gm
Occurrences: Novice D
Farmer John considers himself a bit of a philosopher! He often spends time daydreaming about his favorite thought experiments, including the trolley problem.
One day, Farmer John needed to deploy $$$n$$$ trolleys to transport haybales, where the trolleys are listed in ascending order of weight from left to right, and the trolleys move to the right. Unfortunately, Farmer John's prized cows were taking an afternoon nap and ended up right in the way of the trolleys!
There are two tracks in front of Farmer John's array of trolleys, with each track having $$$a$$$ and $$$b$$$ cows of their own respective weights. Farmer John can choose to redirect trolleys to either track at will. If a trolley is heavier than the cow it collides with, the cow will wake up and run off the track. Otherwise, the cow will remain sleeping on the track. The trolley will always derail after a collision.
Farmer John has no time to deliberate the ethics of redirecting the trolleys; he just wants to prevent as many cows as possible from being awoken. Can you help him out?
The first line contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 \leq n, a, b \leq 2 \cdot 10^5$$$): the number of trolleys we have, the number of cows on our first track, and the number of cows on our second track, respectively.
The second line contains $$$n$$$ integers $$$t_1, t_2, \dots t_n$$$: the weights of our trolleys. It is guaranteed that the trolleys' weights are listed in ascending order. More formally, $$$t_1 \leq t_2 \leq \dots \leq t_n$$$. Note that the trolleys are released in reverse order: that is, $$$t_n$$$ goes first, then $$$t_{n-1}$$$, $$$\dots$$$, and finally $$$t_1$$$.
The third line contains $$$a$$$ integers $$$c_1, c_2, \dots c_a$$$: the weights of the cows on the first track.
The fourth line contains $$$b$$$ integers $$$d_1, d_2, \dots d_b$$$: the weights of the cows on our second track.
Note that for both tracks, the first cow in the list is the first one that would get hit by a trolley, should one be directed onto that track.
It is guaranteed that $$$1 \leq t_i, c_i, d_i \leq 10^9$$$.
If the input format is unclear, please refer to the sample explanation's diagram for further clarification.
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Test $$$1-3$$$ satisfy $$$n, a, b \leq 10$$$
Tests $$$4-7$$$ satisfy $$$n, a, b \leq 10^{3}$$$.
Tests $$$8-20$$$ satisfy no additional constraints.
Output the minimum number of cows that get awoken if Farmer John directs the trolleys optimally.
3 3 3 4 9 10 7 4 9 3 10 8
1
2 1 110 1011
1
Here's a diagram for the first sample test case.
We can show that the following sequence of operations is optimal.
This results in only one cow being woken up, that being the first cow on the second track.
In the second sample test case, we can send all the trolleys to the first track. This results in only one cow being woken up. Note that if a track has no cows, the trolley will pass right through it and derail afterward.
—
Problem Idea: Alex_C
Problem Preparation: eysbutno
Occurrences: Novice E
You are given $$$t$$$ test cases. Each test case is a sequence of five non-negative integers. Your goal is to reduce all five numbers to zero by applying a sequence of operations at minimum total cost.
There are two types of operations:
For each test case, determine the minimum total cost required to reduce all five integers to zero. If it is impossible, output $$$-1$$$.
The first line contains $$$t$$$ ($$$1 \leq t \leq 10^6$$$), the number of test cases. The only line of each test case includes $$$5$$$ integers, the sequence (sum of sequence $$$\le 7 * 10^9$$$).
For each test case, output the minimum cost, or $$$-1$$$ if it is not possible.
31 1 2 2 11 1 2 1 11 0 0 0 0
3 2 -1
Problem Idea: Nyctivoe
Problem Preparation: Nyctivoe
Occurrences: Novice F
Determine the maximum possible width of any possible binary tree constructed with $$$n$$$ nodes.
- A binary tree is defined as any tree where all nodes have at most 2 children.
- The width of a tree is defined as the maximum number of nodes at any level of the tree. Null nodes do not contribute to the width of the tree.
The first line of input will contain an integer $$$t$$$ ($$$1 \leq t \leq 2 \times 10^5$$$), indicating that there are $$$t$$$ test cases. The next $$$t$$$ lines will each contain an integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$), the input for each test case.
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-6$$$ satisfy $$$1 \leq n \leq 10^5$$$.
Tests $$$7-20$$$ satisfy no additional constraints.
Output one integer on a separate line per test case, the maximum possible width of any binary tree constructed with $$$n$$$ nodes.
341017
2 4 8
Problem Idea: Mustela_Erminea
Problem Preparation: Mustela_Erminea
Occurrences: Novice G / Advanced B
You are given an array $$$a$$$ of $$$n$$$ integers $$$a_1,a_2,a_3,\ldots,a_n$$$.
Define $$$f(k)$$$ as the $$$\text{MEX}$$$ of the maximum value of all subarrays of length $$$k$$$.
Print $$$f(k)$$$ for each $$$k$$$ from 1 to n.
More formally, output the values of $$$\text{MEX}^{n-i}_{j=0} \max^{i}_{k=1} a_{j+k}$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$.
A subarray of length $$$k$$$ is an array that contains exactly $$$k$$$ elements obtained by removing a prefix and a suffix from the original array.
The $$$\text{MEX}$$$, or minimal excluded, of a sequence is the smallest non-negative integer not present in that sequence.
The first line contains $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$), the number of elements in the array $$$a$$$.
The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$).
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-6$$$ satisfy $$$n \leq 10^3$$$.
Tests $$$7-8$$$ satisfy $$$a_i=i-1$$$.
Tests $$$9-20$$$ satisfy no additional constraints.
One line containing $$$n$$$ integers, the $$$i$$$-th integer denoting the value of $$$\text{MEX}^{n-i}_{j=0} \max^{i}_{k=1} a_{j+k}$$$ at $$$i$$$.
32 1 0
3 0 0
For $$$k=1$$$, the $$$\max$$$ of each subarray is $$${2, 1, 0}$$$, so the $$$\text{MEX}$$$ is $$$3$$$.
For $$$k=2$$$, the $$$\max$$$ of each subarray isare $$${2, 1}$$$, so the $$$\text{MEX}$$$ is $$$0$$$.
For $$$k=3$$$, the $$$\max$$$ of each subarray isare $$${2}$$$, so the $$$\text{MEX}$$$ is $$$0$$$.
—
Problem Idea: culver0412
Problem Preparation: Jasonwei08
Occurrences: Novice H / Advanced C
Mr. G's students are hanging up pennants! There is a wall with $$$L$$$ slots, and has $$$N$$$ pennants hung on slots $$$1$$$ through $$$N$$$. The pennant in the $$$i$$$-th slot has rank $$$r_i$$$ (not necessarily distinct), and the pennants are ordered by rank, so $$$r_i\le r_{i+1}$$$ for $$$1\le i \lt N$$$. In one second, the students can either take a pennant off of a slot, or put a pennant of any rank onto the wall in any slot.
The students have put up all the pennants already, if they find $$$a$$$ extra pennants of rank $$$k$$$, then they must rearrange the pennants such that every pennant is on the wall, and the pennants are ordered by rank. It is guaranteed that this is always possible in finite time.
Mr. G has $$$q$$$ queries of $$$(a,k)$$$, and wants to find out the minimum time the students will take for each combination of $$$(a,k)$$$. Note that the pennants are not actually rearranged, that is, the queries are independent of each other.
note: the above image is not intended to be an accurate representation of the problem.
The first line of input contains three integers $$$N$$$, $$$Q$$$, and $$$L$$$ ($$$1\le N, Q\le 2\cdot 10^5$$$, $$$N\le L\le 10^9$$$).
The following line contains $$$N$$$ integers $$$r_1, \dots, r_N$$$, ($$$1\le r_i\le N$$$). It is guaranteed that $$$r_i\le r_{i+1}$$$ for $$$1\le i \lt N$$$.
The following $$$q$$$ lines contain two integers $$$a$$$, $$$k$$$, which denote the number and rank of the newly found pennants for each query ($$$1\le a \le L-N$$$, $$$1\le k\le N$$$).
—
Tests in subtasks are numbered from $$$1-20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-3$$$ satisfy $$$N, Q\le 200$$$.
Tests $$$4-20$$$ satisfy no additional constraints.
Output $$$Q$$$ lines, the $$$i$$$-th line containing a single integer, the minimum time (in seconds) the students will take for the $$$i$$$-th query.
5 5 101 3 4 5 52 15 44 24 35 1
10 9 12 10 13
In the first query, it is optimal for the students to take off the last 4 pennants, and then put up the 6 pennants (including the new ones) in order.
—
Problem Idea: jay_jayjay
Problem Preparation: jay_jayjay
Occurrences: Novice I / Advanced D
Alter's friends are playing a game of castlefall! The game has $$$N$$$ players, labelled $$$1$$$ through $$$N$$$, and $$$M$$$ words, labeled $$$1$$$ through $$$M$$$. Each player is assigned to exactly one of two non-empty teams of possibly different sizes, and each team is given one of the $$$M$$$ words. Note that the two teams are given different words.
Since players do not know which team they are on, each player has announced a clue. Specifically, the $$$i$$$-th player has a word in the set $$$S_i$$$.
Since Alter doesn't want to think, he asks you to help him answer the following question: Is it possible to uniquely determine the teams and the words corresponding to each team? If so, Alter will also ask you what the words are.
The first line contains $$$T$$$ ($$$1\le T\le 20$$$), the number of independent test cases. The description of the test cases follows.
The first line of each test case contains two integers $$$N$$$ and $$$M$$$ ($$$1\le N \le 20$$$, $$$1 \le M\le 10^5$$$).
In the following $$$N$$$ lines, the $$$i$$$-th line contains a binary string $$$s_i$$$ of length $$$M$$$. If the $$$j$$$-th character of $$$s_i$$$ is $$$1$$$, then the $$$i$$$-th player can possibly have the $$$j$$$-th word, that is, $$$j$$$ is in the set $$$S_i$$$. Otherwise, it is not possible for the $$$i$$$-th player to have the $$$j$$$-th word, or equivalently, $$$j$$$ is not in the set $$$S_i$$$.
It is guaranteed that the sum of $$$M$$$ over all test cases does not exceed $$$5\cdot 10^5$$$.
—
Tests in subtasks are numbered from $$$1-20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-2$$$ satisfy $$$N\le 10$$$, $$$M\le 10^3$$$.
Tests $$$3-8$$$ satisfy $$$N\le 10$$$.
Tests $$$9-20$$$ satisfy no additional constraints.
For each test case, output a single line with "Yes" if it is possible to uniquely determine both the teams and the words corresponding to each team, or "No" otherwise. If the output is Yes, output a second line with two integers, corresponding to the words given to the two teams, in increasing order.
33 40010011001103 40010000101103 4000111001001
No Yes 3 4 No
In the first sample test case, here are some possible teams:
Since there is not a unique team, the answer is No.
In the second test case, the unique team combination is: The first and third players are on a team with word 3, and the second player is on a team with word 4.
—
Problem Idea: jay_jayjay
Problem Preparation: jay_jayjay
Occurrences: Novice J / Advanced E
You are given a connected weighted graph with $$$n$$$ vertices and $$$m$$$ bidirectional edges. You are to traverse from vertex $$$s$$$ to vertex $$$t$$$.
Across all (not necessarily simple) paths from $$$s$$$ to $$$t$$$, count the number of distinct sums of weights along those paths modulo $$$k$$$.
The first line contains the number of test cases $$$T$$$ ($$$1\leq T \leq 10$$$). The description of the test cases follows.
The first line of each test case contains five space-separated integers, $$$n$$$, $$$m$$$, $$$k$$$, $$$s$$$, and $$$t$$$ ($$$1 \leq n \leq 10^5, n-1 \leq m \leq 2 \cdot 10^5, 1 \leq k \leq 10^9$$$, $$$1 \leq s, t \leq n$$$).
The next $$$m$$$ lines of each test case contain three space-separated integers $$$u$$$, $$$v$$$, and $$$w$$$ ($$$1 \leq u, v \leq n, 0 \leq w \leq 10^9$$$), denoting that an edge of weight $$$w$$$ connects vertices $$$u$$$ and $$$v$$$.
It is guaranteed that the given graph is connected.
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-6$$$ satisfy $$$k \leq 10$$$.
Tests $$$7-20$$$ satisfy no additional constraints.
Output one integer $$$-$$$ the number of possible sums of weights modulo $$$k$$$.
14 5 3 1 41 4 31 2 12 4 22 3 43 4 5
3
In the first test case of the sample, $$$k = 3$$$.
The path $$$1 \rightarrow 4$$$ has a sum of weights $$$3 \equiv 0 \mod 3$$$.
The path $$$1 \rightarrow 2 \rightarrow 3 \rightarrow 4$$$ has a sum of weights $$$10 \equiv 1 \mod 3$$$.
The path $$$1 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 4$$$ has a sum of weights $$$5 \equiv 2 \mod 3$$$.
It can be shown that no other distinct sums of weights modulo $$$3$$$ can be achieved.
—
Problem Idea: culver0412
Problem Preparation: Ryan Fu
Occurrences: Novice K / Advanced F
Given a 2D grid with obstacles, you want to move a robot to point $$$B$$$. To do this, you can summon robots at spawn points marked as $$$A$$$. (As long as it isn't obstructed)
You may also instruct robots to move. A robot can move into an adjacent cell if there is empty space in that cell. However, if there is an obstacle, the movement will be unsuccessful. If there is a robot, the robot is able to push it, as long as the cell it is pushed to is empty. If there is another robot or an obstacle, the movement is unsuccessful. The outside of the grid is made of obstacles, so robots may not move outside the grid.
After a robot is instructed to move, even if the move was unsuccessful, the robot will self destruct and cease to exist, leaving an unoccupied cell. A pushed robot does not self destruct.
Here are $$$5$$$ examples of what happens when the red robot moves to the right:
Your goal is to find the minimum number of robots you need to summon in order to move a robot to point $$$B$$$ (Moving a robot to point $$$B$$$ only for it to immediately self destruct does not count).
If it is impossible to move a robot to point $$$B$$$, print $$$-1$$$.
Additionally, it is guaranteed by the test data that if it is possible to move a robot to point $$$B$$$, it can be done so in at most $$$4 \cdot 10^{18}$$$ summoned robots.
The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 3$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 1000$$$).
The next $$$n$$$ lines of each test case contain $$$m$$$ characters, representing the 2D grid.
If a character on a line is '.', the corresponding cell is empty. If it is '#', the cell is an obstacle. If it is 'A', the cell is a robot spawn point. If it is 'B', the cell is the target destination of the robots.
Once again, the test data guarantees that if it is possible to move a robot to point $$$B$$$, it can be done so in at most $$$4 \cdot 10^{18}$$$ summoned robots.
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Test $$$1$$$ satisfies that there is exactly one 'A' cell.
Tests $$$2-3$$$ satisfy $$$n = 1$$$.
Tests $$$4-10$$$ satisfy $$$n, m \leq 50$$$.
Tests $$$11-20$$$ satisfy no additional constraints.
Print one integer, the minimum number of robots you need to summon in order to move a robot to point $$$B$$$, or $$$-1$$$ if it is impossible.
33 3AA.AA.##B5 5AA...A.##..AAAAA..###.B.#6 6AA....AA...........................B
4 -1 64
For the first testcase of the sample, $$$4$$$ robots are required to push one to $$$B$$$. Here is a visualization:
—
Problem Idea: Alex_C
Problem Preparation: HaccerKat
Occurrences: Novice L / Advanced H