RCC Teen - Task 5 - Bandwidth
RCC Teen - Task 5 - Bandwidth
0,1,0 0,3,0
0,0,0 0,0,1 0,2,0 0,2,1 0,4,0 0,4,1
0,1,1 0,3,1
1,0,0 1,2,0 1,4,0
1,1,0 1,1,1 1,3,0 1,3,1
1,0,1 1,2,1 1,4,1
2,1,0 2,3,0
2,0,0 2,0,1 2,2,0 2,2,1 2,4,0 2,4,1
2,1,1 2,3,1
A (3 × 5) 5G network representation
A 5G network is a n × m grid where each pentagon represents a server. It is possible to index the
servers with a triple (i, j, k) where 0 ≤ i < n is the row, 0 ≤ j < m is the column and k is 0 for left/up
servers or 1 for right/down servers. Following the example of the first figure the network has a total of
2 × n × m = 2 × 3 × 5 = 30 servers.
Each server is directly connected with all the servers with which it shares a side, for example (1, 1, 0) is
connected with (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 1) and (2, 1, 0)
All the tasks are generated on a specific starting server (in green) and must reach a destination server
(in red) using the available connections. Unfortunately, each server has a limited number of tasks, from
0 to 9, that it can manage and exchange in a unit of time, except for the starting and destination servers
which can send and receive an unlimited number of tasks.
This lead to a limited bandwidth, i.e. the number of tasks that can be completed in a unit of time,
between the starting and the destination server.
6 0
0 D 4 3
2 1
3 2
0 1 2 2
2 S
7 9
9 8 5 4
6 0
As we want to speed up the final checks to announce the winners as soon as possible, Reply approves
the budget to upgrade one and only one of the server in the network among those who are not already
at the maximum capacity of 9.
Of course, upgrade a single server does not always speed up the the network, so we’re asking one last
time your support to find a server to upgrade in order to increase the bandwidth.
bandwidth Page 1 of 2
Input data
The first line of the input file contains an integer T, the number of test cases to solve, followed by T
testcases, numbered from 1 to T.
In each test case the first line contains the two integers N and M, the size of the grid.
The following N lines contains a string of length 2 × M , each digit of the string represent the capacity
of a single server, according to the numerical ordering of the indices. The starting server is marked with
a capacity of S, the destination with a capacity of D.
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 words:
Case #t: i j k
where t is the test case number (from 1 to T) and i j k are the coordinate of the server to upgrade.
If there is no single server to upgrade, i.e. there is no solution, use the following format:
Case #t: -1
Constraints
• 1 ≤ T ≤ 16.
• 1 ≤ N, M ≤ 500.
• All the capacities are between 0 and 9.
Scoring
• input 1 : T = 1, N = 1, M ≤ 5.
• input 2 : T = 4, N ≤ 20, M ≤ 20.
• input 3 : T = 8, N ≤ 50, M ≤ 50.
• input 4 : T = 12, N ≤ 100, M ≤ 100.
• input 5 : T = 16, N ≤ 500, M ≤ 500.
Examples
input output
2 Case #1: 1 1 1
3 4 Case #2: -1
0 D624301
32012 S22
98765490
1 5
S11111111D
bandwidth Page 2 of 2