Problem4 Miner
Problem4 Miner
Problem4 Miner
Input data
The first line of the input file contains an integer T, the number of test cases to solve.
For each test case, the first line of the input file contains the integers:
• N, the size of the square grid N × N
• C, the number on different colours of the gems (letter from A-Z a-z)
• Q, the total number of gems
The next Q lines will display the information of the gems:
• the X position on the grid, representing the row, from top to bottom
• the Y position on the grid, representing the column, from left to right
• the G colour of the current gem
Output data
The output file must contain T lines.
For each test case in the input file, the output file must contain a line with the characters:
Case #t: X1 Y1 X2 Y2 A
Where t is the test case number, from 1 to T, X1 Y 1 is the top-left coordinate of the rectangle of the
solution, X2 Y 2 is the bottom-right coordinate, and A is the size of the area.
Note: The lines of the output file must be ordered from Case #1: to Case #T:.
miner Page 1 of 3
Constraints
• T = 5, where T is the number of test cases in input.
• 1 ≤ N ≤ 1 500
• 1 ≤ C ≤ 52
• 1 ≤ Q ≤ 17 5000
Scoring
• input 1 : T = 5, N = 10, C ≤ 5, Q = 30
• input 2 : T = 5, N = 100, C ≤ 10, Q = 600
• input 3 : T = 5, N = 500, C ≤ 20, Q = 2 500
• input 4 : T = 5, N = 1 000, C ≤ 30, Q = 7 500
• input 5 : T = 5, N = 1 500, C ≤ 52, Q = 17 500
Examples
input output
1 Case #1: 4 5 8 6 10
10 4 12
8 6 B
5 9 A
0 2 B
1 8 A
0 5 D
3 3 D
4 6 A
6 5 D
6 6 C
5 2 C
7 1 C
5 8 B
Explanation
In this example, you have an N × N (N = 10) grid with C = 4 colours of gems (represented as A, B,
C and D). The total number of gems is Q = 12.
Here’s what the map looks like:
miner Page 2 of 3
The minimum area in this case is 10 and there are 2 correct solutions: the area from coordinates (4, 5)
to (8, 6) and the area from (5, 5) to (6, 9). Both solutions are considered correct.
miner Page 3 of 3