ゲームフリーク Programming Contest 2023(AtCoder Beginner Contest 317)
G
Rearranging
AtCoder
⌀ 2649
原题
← Ex→
翻译中…

Problem Statement

翻译中…

There is a grid with $N$ rows and $M$ columns. The square at the $i$-th row from the top and the $j$-th column from the left contains the integer $A_{i,j}$. Here, the squares contain $M$ occurrences of each of $1,\ldots,N$, for a total of $NM$ integers.

翻译中…

You perform the following operations to swap the numbers written on the squares.

翻译中…
  • For $i=1,\ldots,N$ in this order, do the following.
  • Freely rearrange the numbers written in the $i$-th row. That is, freely choose a permutation $P=(P_{1},\ldots,P_{M})$ of $1,\ldots,M$, and replace $A_{i,1},\ldots,A_{i,M}$ with $A_{i,P_{1}},\ldots,A_{i,P_{M}}$ simultaneously.
翻译中…

Your goal is to perform the operations so that each column contains each of $1,\ldots,N$ once. Determine if this is possible, and if so, print such a resulting grid.

翻译中…

Constraints

翻译中…
  • $1 \leq N,M \leq 100$
  • $1 \leq A_{i,j} \leq N$
  • All input values are integers.
  • The $NM$ numbers $A_{1,1},\ldots,A_{N,M}$ contain exactly $M$ occurrences of each of $1,\ldots,N$.
翻译中…

Input

翻译中…

The Input is given from Standard Input in the following format:

翻译中…

N M
A_{1,1} \ldots A_{1,M}
\vdots
A_{N,1} \ldots A_{N,M}

翻译中…

Output

翻译中…

If it is impossible to perform the operations so that each column contains each of $1,\ldots,N$ once, print No. Otherwise, print Yes in the first line, and in the subsequent $N$ lines, print a resulting grid where each column contains each of $1,\ldots,N$ once, in the following format. Let $B_{i,j}$ be the number written in the square at the $i$-th row from the top and $j$-th column from the left of the grid. For each $1\leq i \leq N$, the $(i+1)$-th line should contain $B_{i,1},\ldots,B_{i,M}$ in this order, with spaces in between.

翻译中…

If multiple solutions exist, any of them is accepted.

翻译中…

样例

Input #1
3 2
1 1
2 3
2 3
Output #1
Yes
1 1
3 2
2 3
Also, the following output is accepted.
Input #2
4 4
1 2 3 4
1 1 1 2
3 2 2 4
4 4 3 3
Output #2
Yes
1 4 3 2
2 1 1 1
4 2 2 3
3 3 4 4
题目信息
题号
abc317_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。