#abc279c. C - RANDOM

C - RANDOM

Score : 300300 points

问题描述

给定由#.组成的模式SSTT,每种模式都有HH行和WW列。
模式SSHH个字符串的形式给出,其中SiS_i的第jj个字符表示第ii行和第jj列的元素。模式TT也是如此。

判断是否可以通过重新排列SS的列使其与TT相等。

这里,对模式XX的列进行重新排列是按以下方式进行的:

  • 选择一个(1,2,,W)(1,2,\dots,W)的排列P=(P1,P2,,PW)P=(P_1,P_2,\dots,P_W)
  • 然后,对于满足1iH1 \le i \le H的所有整数ii,同时执行以下操作:
    • 对于满足1jW1 \le j \le W的所有整数jj,同时将XX中第ii行和第jj列的元素替换为第ii行和PjP_j列的元素。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given patterns SS and TT consisting of # and ., each with HH rows and WW columns.
The pattern SS is given as HH strings, and the jj-th character of SiS_i represents the element at the ii-th row and jj-th column. The same goes for TT.

Determine whether SS can be made equal to TT by rearranging the columns of SS.

Here, rearranging the columns of a pattern XX is done as follows.

  • Choose a permutation P=(P1,P2,,PW)P=(P_1,P_2,\dots,P_W) of (1,2,,W)(1,2,\dots,W).
  • Then, for every integer ii such that 1iH1 \le i \le H, simultaneously do the following.
    • For every integer jj such that 1jW1 \le j \le W, simultaneously replace the element at the ii-th row and jj-th column of XX with the element at the ii-th row and PjP_j-th column.

Constraints

  • HH and WW are integers.
  • 1H,W1 \le H,W
  • 1H×W4×1051 \le H \times W \le 4 \times 10^5
  • SiS_i and TiT_i are strings of length WW consisting of # and ..

Input

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

HH WW

S1S_1

S2S_2

\vdots

SHS_H

T1T_1

T2T_2

\vdots

THT_H

Output

If SS can be made equal to TT, print Yes; otherwise, print No.

Sample Input 1

3 4
##.#
##..
#...
.###
..##
...#

Sample Output 1

Yes

If you, for instance, arrange the 33-rd, 44-th, 22-nd, and 11-st columns of SS in this order from left to right, SS will be equal to TT.

Sample Input 2

3 3
#.#
.#.
#.#
##.
##.
.#.

Sample Output 2

No

In this input, SS cannot be made equal to TT.

Sample Input 3

2 1
#
.
#
.

Sample Output 3

Yes

It is possible that S=TS=T.

Sample Input 4

8 7
#..#..#
.##.##.
#..#..#
.##.##.
#..#..#
.##.##.
#..#..#
.##.##.
....###
####...
....###
####...
....###
####...
....###
####...

Sample Output 4

Yes

update @ 2024/3/10 11:44:19