ABC Puzzle

AtCoder
IDabc326_d
Time4000ms
Memory256MB
Difficulty
You are given an integer $N$ 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$ [samples]
Samples
Input #1
5
ABCBC
ACAAB
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.
Input #2
3
AAA
BBB
Output #2
No

For this input, there is no way to fill the grid to satisfy the conditions.
API Response (JSON)
{
  "problem": {
    "name": "ABC Puzzle",
    "description": {
      "content": "You are given an integer $N$ 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 ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc326_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an integer $N$ and strings $R$ and $C$ of length $N$ consisting of `A`, `B`, and `C`. Solve the following problem.\nThere is a $N \\times N$ grid. All cells are initially empty.  \nYou can ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments