103263: [Atcoder]ABC326 D - ABC Puzzle

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:6 Solved:0

Description

Score : $450$ points

Problem Statement

You are given an integer $A$ and strings $R$ and $C$ of length $N$ consisting of A, B, and C. Solve the following problem.

There is a $N \times N$ grid. All cells are initially empty.
You can write at most one character from A, B, and C in each cell. (You can also leave the cell empty.)

Determine if it is possible to satisfy all of the following conditions, and if it is possible, print one way to do so.

  • Each row and each column contain exactly one A, one B, and one C.
  • The leftmost character written in the $i$-th row matches the $i$-th character of $R$.
  • The topmost character written in the $i$-th column matches the $i$-th character of $C$.

Constraints

  • $N$ is an integer between $3$ and $5$, inclusive.
  • $R$ and $C$ are strings of length $N$ consisting of A, B, and C.

Input

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

$N$
$R$
$C$

Output

If there is no way to fill the grid to satisfy the conditions in the problem statement, print No in one line.
Otherwise, print one such way to fill the grid in the following format:

Yes
$A_1$
$A_2$
$\vdots$
$A_N$

The first line should contain Yes. The $i$-th of the subsequent $N$ lines should contain a string $A_i$ of length $N$.

  • If the $j$-th character of $A_i$ is ., it indicates that the cell in the $i$-th row from the top and the $j$-th column from the left is empty.
  • If the $j$-th character of $A_i$ is A, it indicates that A is written in the cell in the $i$-th row from the top and the $j$-th column from the left.
  • If the $j$-th character of $A_i$ is B, it indicates that B is written in the cell in the $i$-th row from the top and the $j$-th column from the left.
  • If the $j$-th character of $A_i$ is C, it indicates that C is written in the cell in the $i$-th row from the top and the $j$-th column from the left.

If there are multiple correct ways to fill the grid, you may print any of them.


Sample Input 1

5
ABCBC
ACAAB

Sample Output 1

Yes
AC..B
.BA.C
C.BA.
BA.C.
..CBA

The grid in the output example satisfies all the following conditions, so it will be treated as correct.

  • Each row contains exactly one A, one B, and one C.
  • Each column contains exactly one A, one B, and one C.
  • The leftmost characters written in the rows are A, B, C, B, C from top to bottom.
  • The topmost characters written in the columns are A, C, A, A, B from left to right.

Sample Input 2

3
AAA
BBB

Sample Output 2

No

For this input, there is no way to fill the grid to satisfy the conditions.

Output

得分:450分 部分 问题描述 你得到了一个整数N和长度为N的字符串R和C,由A、B和C组成。解决以下问题。 有一个N×N的网格。所有单元格最初都是空的。 你可以在每个单元格中最多写一个来自A、B和C的字符(也可以留空)。 确定是否有可能满足以下所有条件,如果可能,请打印一种方法。 - 每行和每列都恰好包含一个A、一个B和一个C。 - 第i行最左边的字符与R的第i个字符匹配。 - 第i列最上面的字符与C的第i个字符匹配。 部分 约束 - N是3到5之间的整数,包括3和5。 - R和C是长度为N的字符串,由A、B和C组成。 输入格式 输入将从标准输入中以以下格式给出: $N$ $R$ $C$ 输出格式 如果无法在满足问题描述中的条件的情况下填充网格,请在一行中打印No。 否则,以下格式打印一种满足条件的填充网格的方法: Yes $A_1$ $A_2$ $\vdots$ $A_N$ 第一行应包含Yes。 接下来的N行应包含长度为N的字符串$A_i$。 - 如果$A_i$的第j个字符是.,表示从上数第i行、从左数第j列的单元格为空。 - 如果$A_i$的第j个字符是A,表示从上数第i行、从左数第j列的单元格中写有A。 - 如果$A_i$的第j个字符是B,表示从上数第i行、从左数第j列的单元格中写有B。 - 如果$A_i$的第j个字符是C,表示从上数第i行、从左数第j列的单元格中写有C。 如果有多

HINT

n*n字符矩阵,填入abc,要求每一行每一列均恰好abc各出现一次,且从上往下最左边的字符序列为R,从左往右最上面的字符序列为C,是否有解,如果有输出一种方案?

加入题单

算法标签: