#P15126. [ICPC 2024 LAC] LED Matrix

[ICPC 2024 LAC] LED Matrix

题目描述

A LED matrix is a two-dimensional array of LEDs that is used to display information. This is achieved by turning on the LEDs that form a desired pattern. The figure below represents a LED matrix displaying a smiling-face pattern. LEDs that are turned off are shown in white, while LEDs that are turned on appear colored.

:::align{center} :::

Some LED matrices scroll the pattern from right to left across the matrix, turning on just the appropriate LEDs at each step. Thus, any pattern with the same height than the matrix can be displayed, even patterns that are wider than the matrix. The pattern scrolling works as follows: Initially, all the LEDs in the matrix are turned off. The next step, the last column of the matrix displays the first column of the pattern. At each new step the pattern is moved one column to the left across the matrix, until the first column of the matrix displays the last column of the pattern. Finally, all the LEDs in the matrix are turned off again. If a LED matrix is equipped with pattern scrolling, the scrolling occurs even if the pattern is not wider than the matrix.

The picture below shows all the steps required to display a pattern of an arrow that is pointing to the left.

:::align{center} :::

Astrid has just received an old LED matrix with pattern scrolling, and she thinks that some LEDs might be broken. Since broken LEDs cannot be turned on, she is worried that some patterns will not display properly. Given the description of the state of each LED, and the pattern to display, you must tell whether the appropriate LEDs can be turned on at every step of the pattern scrolling.

输入格式

The first line contains three integers RR, CC and KK (1R,C,K10001 \le R, C, K \le 1000), indicating respectively the number of rows of both the LED matrix and the pattern, the number of columns of the matrix, and the number of columns of the pattern.

The next RR lines describe the matrix and the pattern from top to bottom. Each of these lines contains a string MM of length CC and a string PP of length KK, describing respectively a row of the matrix and a row of the pattern. Each character of both MM and PP is either * (asterisk) or “-” (hyphen). For MM, the character * indicates a good LED while the character “-” represents a broken LED. For PP, the character * indicates a LED that must be turned on while the character “-” represents a LED that must be turned off.

输出格式

Output a single line with the uppercase letter “Y” if the appropriate LEDs can be turned on at every step of the pattern scrolling, and the uppercase letter “N” otherwise.

6 6 6
****** --*---
****** -**---
****** ******
****** ******
****** -**---
*****- --*---
N
2 4 6
**** ------
***- *-----
N
2 6 4
****** ****
*-**-* ----
Y
1 1 1
* *
Y
1 1 1
* -
Y