atcoder#ABC300B. [ABC300B] Same Map in the RPG World
[ABC300B] Same Map in the RPG World
Score : points
Problem Statement
Takahashi is developing an RPG. He has decided to write a code that checks whether two maps are equal.
We have grids and with horizontal rows and vertical columns. Each cell in the grid has a symbol
#
or.
written on it. The symbols written on the cell at the -th row from the top and -th column from the left in and are denoted by and , respectively.
The following two operations are called a vertical shift and horizontal shift.
- For each , simultaneously do the following:- simultaneously replace with .
- simultaneously replace with .
- For each , simultaneously do the following:- simultaneously replace with .
- simultaneously replace with .
Is there a pair of non-negative integers that satisfies the following condition? Print Yes
if there is, and No
otherwise.
- After applying a vertical shift times and a horizontal shift times, is equal to .
Here, is said to be equal to if and only if for all integer pairs such that and .
Constraints
- is
#
or.
, and so is . - and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if there is a conforming integer pair ; print No
otherwise.
4 3
..#
...
.#.
...
#..
...
.#.
...
Yes
By choosing , the resulting is equal to . We describe the procedure when is chosen. Initially, is as follows.
..#
...
.#.
...
We first apply a vertical shift to make as follows.
...
.#.
...
..#
Then we apply another vertical shift to make as follows.
.#.
...
..#
...
Finally, we apply a horizontal shift to make as follows, which equals .
#..
...
.#.
...
3 2
##
##
#.
..
#.
#.
No
No choice of makes equal .
4 5
#####
.#...
.##..
..##.
...##
#...#
#####
...#.
Yes
10 30
..........##########..........
..........####....###.....##..
.....##....##......##...#####.
....####...##..#####...##...##
...##..##..##......##..##....#
#.##....##....##...##..##.....
..##....##.##..#####...##...##
..###..###..............##.##.
.#..####..#..............###..
#..........##.................
................#..........##.
######....................####
....###.....##............####
.....##...#####......##....##.
.#####...##...##....####...##.
.....##..##....#...##..##..##.
##...##..##.....#.##....##....
.#####...##...##..##....##.##.
..........##.##...###..###....
...........###...#..####..#...
Yes