#P9028. [COCI 2022/2023 #1] Desni klik

[COCI 2022/2023 #1] Desni klik

Background

NFP means the future. When it comes to finance, Noa’s friends all want to hear him say this.

Problem Description

NFP is a cryptocurrency. The value of one NFP over ss days can be represented by an rr-row, ss-column character matrix containing only the characters . and #. In column ii, the # in the jj-th row from bottom to top means that on day ii the value of this NFP is jj.

The “insecurity” of an NFP is defined as the difference between the maximum value it reaches and the minimum value it reaches over the ss days.

....##.
#..#...
.##....
......#

As shown above, the values of this NFP over 77 days are: 3,2,2,3,4,4,13,2,2,3,4,4,1. Its “insecurity” is 33.

Now Noa wants you to help him determine the insecurity of the nn NFPs he has.

Input Format

The first line contains three integers n,r,sn, r, s, representing the number of NFPs, the number of rows of the matrix, and the number of columns.

Then follow nn matrices of size r×sr \times s, describing the values of each NFP over ss days.

It is guaranteed that in the value matrix of each NFP, every column contains exactly one character #.

Output Format

Output nn lines, each being the insecurity of one NFP.

4 2 2
##
..
..
##
#.
.#
.#
#.
0
0
1
1
1 5 8
.....#.#
...#..#.
..#.#...
.#......
#.......
4
2 3 3
...
##.
..#
.#.
#..
..#
1
2

Hint

Subtask Score Special Property
11 55 r=s=2r=s=2
22 1515 n=1n=1
33 3030 No special property

For 100%100\% of the testdata, 1n201 \leq n \leq 20, 2r,s502 \leq r, s \leq 50.

The full score for this problem is 5050 points.

Translated by ChatGPT 5