#abc237b. B - Matrix Transposition

B - Matrix Transposition

Score : 200200 points

问题描述

给定一个 HH×WW 的矩阵 AA

AA 中从上数第 ii 行、从左数第 jj 列的元素为 Ai,jA_{i,j}

BB 为一个 WW×HH 的矩阵,其中从上数第 ii 行、从左数第 jj 列的元素等于 Aj,iA_{j, i}

即,矩阵 BB 是矩阵 AA 的转置。

输出矩阵 BB

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given an HH-by-WW matrix AA.
The element at the ii-th row from the top and jj-th column from the left of AA is Ai,jA_{i,j}.

Let BB be a WW-by-HH matrix whose element at the ii-th row from the top and jj-th column from the left equals Aj,iA_{j, i}.
That is, BB is the transpose of AA.

Print BB.

Constraints

  • 1H,W1051\leq H,W \leq 10^5
  • H×W105H \times W \leq 10^5
  • 1Ai,j1091 \leq A_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

HH WW

A1,1A_{1,1} A1,2A_{1,2} \ldots A1,WA_{1,W}

A2,1A_{2,1} A2,2A_{2,2} \ldots A2,WA_{2,W}

\vdots

AH,1A_{H,1} AH,2A_{H,2} \ldots AH,WA_{H,W}

Output

Print BB in the following format:

B1,1B_{1,1} B1,2B_{1,2} \ldots B1,HB_{1,H}

B2,1B_{2,1} B2,2B_{2,2} \ldots B2,HB_{2,H}

\vdots

BW,1B_{W,1} BW,2B_{W,2} \ldots BW,HB_{W,H}

Sample Input 1

4 3
1 2 3
4 5 6
7 8 9
10 11 12

Sample Output 1

1 4 7 10
2 5 8 11
3 6 9 12

For example, we have A2,1=4A_{2,1}=4, so the element at the 11-st row from the top and 22-nd column from the left of the transpose BB is 44.

Sample Input 2

2 2
1000000000 1000000000
1000000000 1000000000

Sample Output 2

1000000000 1000000000
1000000000 1000000000

update @ 2024/3/10 10:15:12