

実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 点
問題文
行 列のグリッドがあります。高橋君は以下の条件を満たすように各マスを黒または白のいずれかに塗り分けたいと考えています。
- すべての行について以下の条件が成り立つ。
- ある整数 が存在して、その行の左から 個のマスは黒、それ以外は白で塗られている。
- すべての列について以下の条件が成り立つ。
- ある整数 が存在して、その列の上から 個のマスは黒、それ以外は白で塗られている。
個のマスがすでに塗られています。そのうち 個目は上から 行目、左から 列目のマスで、 が B
のとき黒で、 W
のとき白で塗られています。
高橋君はまだ塗られていない残りの 個のマスの色をうまく決めることで条件を満たすことができるか判定してください。
制約
- は
B
またはW
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
条件を満たすことができるとき Yes
を、そうでないとき No
を出力せよ。
入力例 1Copy
4 3 4 1 B 3 2 W 1 3 B
出力例 1Copy
Yes
例えば以下の図のように色を塗り分けると条件を満たすことができます。すでに塗られているマスを赤色の線で囲んでいます。
入力例 2Copy
2 2 1 2 W 2 2 B
出力例 2Copy
No
塗られていない残りの つのマスをどのように塗っても,条件を満たすことはできません。
入力例 3Copy
1 1 1 1 W
出力例 3Copy
Yes
入力例 4Copy
2289 10 1700 1083 W 528 967 B 1789 211 W 518 1708 W 1036 779 B 136 657 B 759 1497 B 902 1309 B 1814 712 B 936 763 B
出力例 4Copy
No
Score : points
Problem Statement
There is an grid. Takahashi wants to color each cell black or white so that all of the following conditions are satisfied:
- For every row, the following condition holds:
- There exists an integer such that the leftmost cells are colored black, and the rest are colored white.
- For every column, the following condition holds:
- There exists an integer such that the topmost cells are colored black, and the rest are colored white.
Out of these cells, of them have already been colored. Among them, the -th one is at the -th row from the top and the -th column from the left, and it is colored black if is B
and white if is W
.
Determine whether he can color the remaining uncolored cells so that all the conditions are satisfied.
Constraints
- is
B
orW
. - All input numbers are integers.
Input
The input is given from Standard Input in the following format:
Output
If it is possible to satisfy the conditions, print Yes
; otherwise, print No
.
Sample Input 1Copy
4 3 4 1 B 3 2 W 1 3 B
Sample Output 1Copy
Yes
For example, one can color the grid as in the following figure to satisfy the conditions. The cells already colored are surrounded by red borders.
Sample Input 2Copy
2 2 1 2 W 2 2 B
Sample Output 2Copy
No
No matter how the remaining two cells are colored, the conditions cannot be satisfied.
Sample Input 3Copy
1 1 1 1 W
Sample Output 3Copy
Yes
Sample Input 4Copy
2289 10 1700 1083 W 528 967 B 1789 211 W 518 1708 W 1036 779 B 136 657 B 759 1497 B 902 1309 B 1814 712 B 936 763 B
Sample Output 4Copy
No