A - First Grid Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

2 行、横 2 列のグリッド(各マスが正方形のマス目)があります。
このグリッドは、各マスが黒か白であり、少なくとも 2 つの黒マスを含みます。
各マスの色の情報は文字列 S_1,S_2 として、以下の形式で与えられます。

  • 文字列 S_ij 文字目が # であれば上から i マス目、左から j マス目は黒
  • 文字列 S_ij 文字目が . であれば上から i マス目、左から j マス目は白

2 つの異なる黒マス同士が辺で接している時、またその時に限りそれら 2 つの黒マスは直接行き来できます。
黒マスのみをいくつか通ることによって、どの 2 つの黒マス同士も(直接または間接的に)行き来できるかどうか判定してください。

制約

  • S_1,S_2# または . からなる 2 文字の文字列
  • S_1,S_2# が合計で 2 つ以上含まれる

入力

入力は以下の形式で標準入力から与えられる。

S_1
S_2

出力

どの 2 つの黒マス同士も行き来できるなら Yes 、そうでないなら No と出力せよ。


入力例 1

##
.#

出力例 1

Yes

左上の黒マスと右上の黒マス、右上の黒マスと右下の黒マスを直接行き来することができます。
これらの移動を用いてどの黒マスからどの黒マスへも行き来できるので、答えは Yes となります。


入力例 2

.#
#.

出力例 2

No

右上の黒マスと左下の黒マスを行き来することはできません。答えは No となります。

Score : 100 points

Problem Statement

We have a grid with 2 horizontal rows and 2 vertical columns.
Each of the squares is black or white, and there are at least 2 black squares.
The colors of the squares are given to you as strings S_1 and S_2, as follows.

  • If the j-th character of S_i is #, the square at the i-th row from the top and j-th column from the left is black.
  • If the j-th character of S_i is ., the square at the i-th row from the top and j-th column from the left is white.

You can travel between two different black squares if and only if they share a side.
Determine whether it is possible to travel from every black square to every black square (directly or indirectly) by only passing black squares.

Constraints

  • Each of S_1 and S_2 is a string with two characters consisting of # and ..
  • S_1 and S_2 have two or more #s in total.

Input

Input is given from Standard Input in the following format:

S_1
S_2

Output

If it is possible to travel from every black square to every black square, print Yes; otherwise, print No.


Sample Input 1

##
.#

Sample Output 1

Yes

It is possible to directly travel between the top-left and top-right black squares and between top-right and bottom-right squares.
These two moves enable us to travel from every black square to every black square, so the answer is Yes.


Sample Input 2

.#
#.

Sample Output 2

No

It is impossible to travel between the top-right and bottom-left black squares, so the answer is No.