Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Problem4 Miner

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Reply Code Challenge - Teen Edition 2023

9 March 2023 miner • EN

Problem 4 - Miner (miner)


A gem miner in the metaverse has to collect gems hidden in a field to complete her awards collection.
If the miner collects at least one gem of each colour, she will win a trophy. Ther’s only one problem:
excavating the meta-field is expensive and only one rectangular/square hole can be dug in the ground.
So, given a map, she needs to find the minimum area that allows her to collect every colour of gem.
The field is an N × N grid, where the top left corner has coordinate (0,0).
Your goal is to find at least one gem of each colour, with minimum effort, by excavating as little area as
possible. The colours of gems are represented by uppercase and lowercase letters (A-Z and a-z) of the
English alphabet. Different zones with the same area could contain all the colours and all are a valid
solution.
Calculate the minimum rectangular area that contains at least one gem of each colour.

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.

The output can be:


Case #1: 4 5 8 6 10
or
Case #1: 5 5 6 9 10

miner Page 3 of 3

You might also like