#K44992. Nearest Treasure Clues

    ID: 27654 Type: Default 1000ms 256MiB

Nearest Treasure Clues

Nearest Treasure Clues

You are given several test cases, each with a path of positions represented by integers. In the path, the integer 0 indicates the presence of a treasure, and 1 indicates an empty position. Your task is to compute, for each position, the distance to the nearest treasure. The distance between two positions i and j is given by \( |i - j| \). If a position has a treasure, its distance is 0. If there is no treasure anywhere on the path for an empty position, output inf for that position.

The problem requires you to process multiple test cases. For each test case, you will first read an integer N (the length of the path), followed by N integers (each either 0 or 1) representing the path. You need to compute and output the clues for each test case, where each clue represents the minimum distance to a treasure along the path.

inputFormat

The input is read from standard input and is formatted as follows:

T
N1
a1 a2 ... aN1
N2
b1 b2 ... bN2
...
NT
c1 c2 ... cNT

Where T is the number of test cases. For each test case, an integer N is provided which indicates the number of positions in the path, followed by N space separated integers (either 0 or 1).

outputFormat

For each test case, output a single line containing N space separated values. Each value is either an integer representing the minimum distance to the nearest treasure, or inf (if no treasure is available in the path for that position).

The output is printed to standard output.

## sample
2
5
1 0 0 1 1
6
1 1 0 1 1 0
1 0 0 1 2

2 1 0 1 1 0

</p>