Brought Down the Grading Server?

시간 제한2초메모리 제한1024 MB

요약
각 코어가 받은 제출물 목록을 재배열해, 매 분마다 모든 코어에서 동시에 평가되는 작업별 제출물 수의 최댓값과 최솟값 차이가 1 이하가 되도록 한다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 수학, 구현
정답자
아직 제출이 없습니다

문제

A hectic first competition day has passed… While the Scientific Committee narrowly fought off the hacking attack on the grading server, they fear that it affected the scoring of the submissions. There is only one option: all submissions have to be rejudged!

The grading server has NN processor cores. The committee has already assigned a list of SS submissions to each core, where each submission is to one of the TT tasks of the competition (numbered 1,…,T1, \dots , T). The committee made sure that SS is a power of two.* Now, in the next SS minutes, each core will evaluate exactly one submission from its list per minute.

Unfortunately, the database containing the task data is quite fragile and could crash if the number of simultaneous requests for a single task’s data varies widely. Therefore, the committee wants to order the submissions of each core in such a way that, during the rejudging, the maximum and minimum number of simultaneously evaluated submissions for any single task differ by at most one.

Write a program which computes such an ordered assignment of the submissions to the cores.


* Due to a bug,† the judging system would crash otherwise, taking down all firewalls and potentially exposing sensitive information!

† You had one job, Wolfgang!

입력

The first line of input contains the three integers NN, SS, and TT described above.

Then, NN lines follow describing the submissions assigned to the cores. The ii-th of these lines contains SS integers t_1,…,t_St\_1 , \dots , t\_S (1≤t_j≤T1 ≤ t\_j ≤ T), meaning that the ii-th core is assigned submissions to the tasks t_1,…,t_St\_1 , \dots , t\_S respectively.

출력

Your program should output NN lines that describe an ordered assignment of the submissions to the cores such that the maximum and minimum number of simultaneously evaluated submissions for any single task differ by at most one: The ii-th of these lines should contain SS integers r_1,…,r_Sr\_1 , \dots , r\_S, meaning that the ii-th core evaluates a submission to task r_jr\_j during the jj-th minute. It is guaranteed that such an assignment exists for each testcase.

힌트

In the output of the first example, the difference between the maximum and the minimum number of simultaneously evaluated submissions is one for tasks 11 and 22 and zero for task 33. On the other hand, ordering the submissions as in the input would not have constituted a valid output because the difference between the maximum and the minimum number of simultaneously evaluations submissions for task 33 is two.

In the output of the second example, the difference between the maximum and the minimum number of simultaneously evaluated submissions is zero for all three tasks.

예제2

  1. 예제 1

    입력
    3 2 3
    1 2
    2 3
    2 3
    
    예상 출력
    2 1
    3 2
    2 3
    
  2. 예제 2

    입력
    3 4 3
    2 3 2 2
    2 3 3 2
    2 2 3 2
    
    예상 출력
    2 2 2 3
    3 2 3 2
    2 3 2 2