#abc326d. D - ABC Puzzle
D - ABC Puzzle
Score : points
问题描述
你将获得一个整数 和两个长度为 的字符串 和 ,由字符 A
、B
和 C
组成。请解决以下问题。
存在一个 的网格,所有单元格最初为空。
你可以在每个单元格中最多写入一个来自 A
、B
和 C
的字符。(也可以选择让单元格保持为空。)
判断是否可能满足以下所有条件,如果可能,则输出一种满足条件的方法。
- 每行和每列恰好包含一个
A
、一个B
和一个C
。 - 第 行最左边书写的字符与字符串 的第 个字符相匹配。
- 第 列顶部书写的字符与字符串 的第 个字符相匹配。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given an integer and strings and of length consisting of A
, B
, and C
. Solve the following problem.
There is a 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
, oneB
, and oneC
. - The leftmost character written in the -th row matches the -th character of .
- The topmost character written in the -th column matches the -th character of .
Constraints
- is an integer between and , inclusive.
- and are strings of length consisting of
A
,B
, andC
.
Input
The input is given from Standard Input in the following format:
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
The first line should contain Yes
. The -th of the subsequent lines should contain a string of length .
-
If the -th character of is
.
, it indicates that the cell in the -th row from the top and the -th column from the left is empty. -
If the -th character of is
A
, it indicates thatA
is written in the cell in the -th row from the top and the -th column from the left. -
If the -th character of is
B
, it indicates thatB
is written in the cell in the -th row from the top and the -th column from the left. -
If the -th character of is
C
, it indicates thatC
is written in the cell in the -th row from the top and the -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
, oneB
, and oneC
. - Each column contains exactly one
A
, oneB
, and oneC
. - 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.
update @ 2024/3/10 01:49:29