#abc375c. C - Spiral Rotation

C - Spiral Rotation

Score : 400400 points

问题陈述

你有一个 NNNN 列的网格,其中 NN 是一个偶数。用 (i,j)(i, j) 表示从顶部数第 ii 行和从左边数第 jj 列的单元格。

每个单元格被涂成黑色或白色。如果 Ai,j=A_{i, j} = #,单元格 (i,j)(i, j) 是黑色的;如果 Ai,j=A_{i, j} = .,它是白色的。

在按照 i=1,2,,N2i = 1, 2, \ldots, \frac{N}{2} 的顺序执行以下操作后,找出每个单元格的颜色。

  • 对于所有在 iiN+1iN + 1 - i 之间的整数对 x,yx, y(包括 iiN+1iN + 1 - i),将单元格 (y,N+1x)(y, N + 1 - x) 的颜色替换为单元格 (x,y)(x, y) 的颜色。对于所有这样的整数对 x,yx, y同时执行这些替换。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a grid with NN rows and NN columns, where NN is an even number. Let (i,j)(i, j) denote the cell at the ii-th row from the top and jj-th column from the left.

Each cell is painted black or white. If Ai,j=A_{i, j} = #, cell (i,j)(i, j) is black; if Ai,j=A_{i, j} = ., it is white.

Find the color of each cell after performing the following operation for i=1,2,,N2i = 1, 2, \ldots, \frac{N}{2} in this order.

  • For all pairs of integers x,yx, y between ii and N+1iN + 1 - i, inclusive, replace the color of cell (y,N+1x)(y, N + 1 - x) with the color of cell (x,y)(x, y). Perform these replacements simultaneously for all such pairs x,yx, y.

Constraints

  • NN is an even number between 22 and 30003000, inclusive.
  • Each Ai,jA_{i, j} is # or ..

Input

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

NN

A1,1A1,2A1,NA_{1,1}A_{1,2}\ldots A_{1,N}

A2,1A2,2A2,NA_{2,1}A_{2,2}\ldots A_{2,N}

\vdots

AN,1AN,2AN,NA_{N,1}A_{N,2}\ldots A_{N,N}

Output

After all operations, let Bi,j=B_{i, j} = # if cell (i,j)(i, j) is black, and Bi,j=B_{i, j} = . if it is white. Print the grid in the following format:

B1,1B1,2B1,NB_{1,1}B_{1,2}\ldots B_{1,N}

B2,1B2,2B2,NB_{2,1}B_{2,2}\ldots B_{2,N}

\vdots

BN,1BN,2BN,NB_{N,1}B_{N,2}\ldots B_{N,N}

Sample Input 1

8
.......#
.......#
.####..#
.####..#
.##....#
.##....#
.#######
.#######

Sample Output 1

........
#######.
#.....#.
#.###.#.
#.#...#.
#.#####.
#.......
########

The operations change the colors of the grid cells as follows:

.......#   ........   ........   ........   ........
.......#   ######..   #######.   #######.   #######.
.####..#   ######..   #....##.   #.....#.   #.....#.
.####..# → ##..##.. → #....##. → #.##..#. → #.###.#.
.##....#   ##..##..   #..####.   #.##..#.   #.#...#.
.##....#   ##......   #..####.   #.#####.   #.#####.
.#######   ##......   #.......   #.......   #.......
.#######   ########   ########   ########   ########

Sample Input 2

6
.#.#.#
##.#..
...###
###...
..#.##
#.#.#.

Sample Output 2

#.#.#.
.#.#.#
#.#.#.
.#.#.#
#.#.#.
.#.#.#

Sample Input 3

12
.......#.###
#...#...#..#
###.#..#####
..#.#.#.#...
.#.....#.###
.......#.#..
#...#..#....
#####.......
...#...#.#.#
..###..#..##
#..#.#.#.#.#
.####.......

Sample Output 3

.#..##...##.
#.#.#.#.#...
###.##..#...
#.#.#.#.#...
#.#.##...##.
............
............
.###.###.###
...#...#.#..
.###...#.###
...#...#...#
.###...#.###