#P3895. [湖南集训] Hungry Rabbit

[湖南集训] Hungry Rabbit

Description

A terrible flood struck unexpectedly in the summer, and the Rabbit Kingdom suffered an unprecedented famine. They have to go to the forest to look for food.

For simplicity, suppose there are nn rabbits in the kingdom, numbered 11 to nn. During the mm days before relief arrives, exactly kk rabbits must go to the forest each day to gather food. Ferocious wolves live in the forest, but fortunately the rabbits have figured out the wolves’ hunting pattern: on each day, the wolves only hunt rabbits with certain indices. For safety, the kk rabbits sent out each day must all be ones that will not be hunted that day.

Because the rabbits going out differ from day to day, they define for each day a newcomer count pip_i: the number of rabbits that go out on day ii but did not go out on day i1i - 1. By convention, p1=0p_1 = 0.

Now the rabbits want, under the safety requirement, that the newcomer count each day does not exceed ll. Please construct a valid plan.

Input Format

The first line contains four integers n,m,k,ln, m, k, l.

The next nn lines each contain a binary string of length mm. In the ii-th line, if the jj-th character is 00, then on day jj rabbit ii will be hunted; if it is 11, then rabbit ii will not be hunted on that day.

Output Format

Output mm lines. Each line should contain kk distinct integers between 11 and nn, representing the indices of the rabbits that go out to gather food on that day.

If there is no valid plan, output a single line with -1.

5 4 3 1
1001
1101
1111
1110
0111
2 3 4
2 3 4
3 4 5
2 3 5

Hint

Sample 1 Explanation

For the sample, over the 44 days, the sets of rabbits going out are respectively {2, 3, 4}; {2, 3, 4}; {3, 4, 5}; {2, 3, 5}.

Constraints

  • For 20%20\% of the testdata, 1n,m101 \le n, m \le 10.
  • For 100%100\% of the testdata, 1n,m8001 \le n, m \le 800, 1kn1 \le k \le n, 1lk1 \le l \le k.

Translated by ChatGPT 5