QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 2048 MB Total points: 100

#8679. 傾けるタイル

Statistics

屋根裏の古いおもちゃの箱から、変わったパズルを見つけました。このパズルは $h \times w$ 個の正方形のマスからなる長方形の盤です。図 F.1 のように、一部のマスには色付きのタイルが置かれています。

problem_8679_141bfaa0ba0c1196198d6deee1100655.png

図 F.1:色付きのタイルは入力例 1 の初期配置に対応します。

このパズルの正確な目的はまだ分かりませんが、タイルを並べ替える方法を調べ始めました。配置は、盤を左、右、手前、奥という四つの主要な方向のいずれかに傾けることで変えられます。傾けると、すべてのタイルがその方向へ滑り、盤の端または別のタイルに遮られるまで動きます。初期配置と最終配置が与えられるので、前者を後者に変える傾け操作の列が存在するか判定してください。図 F.2 は入力例 1 のパズルを傾ける様子です。

problem_8679_eb20e1509cd290b03249b30fb584f1df.png

図 F.2:入力例 1 の解法。

入力

入力の最初の行には整数 $h$ と $w$($1 \le h,w \le 500$)があり、盤の高さと幅を表します。続く $h$ 行で、上の行から下の行へ順に初期配置を示します。各行には長さ $w$ の文字列があり、その行のマスを左から右へ記述します。空のマスに対応する文字はピリオド(.)です。タイルがある場合、その色を小文字(a-z)で表します。異なる文字は異なる色を表し、同じ色のタイル同士は区別できません。

初期配置の後に空行が一つあり、続いて最終配置を表す $h$ 行があります。形式は初期配置と同じです。

出力

初期配置を最終配置に変える傾け操作の列が存在すれば yes、そうでなければ no を出力してください。

入出力例

入力 1

4 4
.r..
rgyb
.b..
.yr.

yrbr
..yr
...g
...b

出力 1

yes

入力 2

1 7
....x..

..x....

出力 2

no

入力 3

4 3
yr.
..b
ry.
b..

...
..b
.ry
byb

出力 3

no

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.