Problem G
Claw Machine
Languages
en
sv
Olivia and Anton are at Liseberg, where they’ve found a claw
machine with
The two-dimensional claw machine can be modeled as a grid of
size
In a single move, Olivia can choose a stuffed animal that does not have any other stuffed animal directly above it and lift it out of the claw machine. Since Olivia hasn’t asked Anton about his favorite animal yet, she wants to know, for each stuffed animal, how many moves she will need to make in total before she can lift it.
Input
The first line contains the integers
Output
For each stuffed animal
Scoring
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.
Group |
Points |
Constraints |
|
|
|
|
|
|
|
|
|
|
|
Each stuffed animal has a rectangular shape. |
|
|
|
|
|
|
|
|
No additional constraints. |
Explanation of Sample 1
In sample 1, the claw machine looks like this:
![\includegraphics[width=0.5\textwidth ]{example.png}](/problems/gosedjur/file/statement/en/img-0001.png)
To lift stuffed animal
Here is how it looks after lifting stuffed animal
![\includegraphics[width=0.35\textwidth ]{example2.png}](/problems/gosedjur/file/statement/en/img-0002.png)
Explanation of Sample 4
Neither stuffed animal
Sample Input 1 | Sample Output 1 |
---|---|
7 4 4 1 3 3 6 1 4 4 4 1 7 4 5 1 2 4 5 |
0 4 0 2 3 0 3 |
Sample Input 2 | Sample Output 2 |
---|---|
4 5 1 2 1 1 3 4 |
1 0 2 3 |
Sample Input 3 | Sample Output 3 |
---|---|
5 4 5 1 1 2 2 3 1 1 2 2 3 4 2 2 2 3 4 2 5 2 3 |
0 1 0 1 2 |
Sample Input 4 | Sample Output 4 |
---|---|
4 4 4 1 1 2 2 3 3 3 2 3 4 3 2 3 3 3 2 |
0 0 -1 -1 |