COCI '22 Contest 1 #1 Desni Klik

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

NFP is the future!, this is something all of Noa's friends can expect him to say when finance topics come up.

NFP is one of the cryptocurrencies. The value of NFP over the course of s days can be represented with a matrix with r rows and s columns, consisting only of characters . and #. The character # in the i-th column represents the value of NFP on the i-th day, with the value being the number of the row, counted bottom-up.


....##.
#..#...
.##....
......#
The value of NFP from the second example over the course of 7 days was: 3, 2, 2, 3, 4, 4, 1. The insecurity of this NFP is 3.

The insecurity of NFP is defined as the difference between the maximum and minimum value it achieves over the course of s days.

Noa wants to determine the insecurity for n NFPs, whose values are represented by matrices with r rows and s columns.

Help him determine the insecurity of each of the n NFPs.

Input Specification

The first line contains integers n, r, and s (1 \le n \le 20, 2 \le r, s \le 50), the number of NFPs, and the number of rows and columns of the matrices.

n matrices follow, one below another, each with r rows and s columns, representing NFP values. Each column consists only of characters ., except for exactly one character #.

Output Specification

Print n lines. In the i-th of n, lines print the insecurity of the i-th NFP.

Constraints

Subtask Points Constraints
1 5 r = s = 2
2 15 n = 1
3 30 No additional constraints.

Sample Input 1

4 2 2
##
..
..
##
#.
.#
.#
#.

Sample Output 1

0
0
1
1

Explanation for Sample Output 1

The values of the first and the second NFP do not change over the days, so their insecurities are equal to 0. The value of the third NFP decreases by 1 on the second day, so the insecurity is equal to 1. The value of the fourth NFP increases by 1 on the second day, so the insecurity is equal to 1.

Sample Input 2

1 5 8
.....#.#
...#..#.
..#.#...
.#......
#.......

Sample Output 2

4

Explanation for Sample Output 2

The maximum value NFP has is 5 (on days 6 and 8), and the minimum value is 1 (on day 1). Therefore, the insecurity is equal to 5 - 1 = 4.

Sample Input 3

2 3 3
...
##.
..#
.#.
#..
..#

Sample Output 3

1
2

Comments

There are no comments at the moment.