QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100 Difficulty: [show]

#1811. 豆の動かし方

Statistics

$H$ 行 $W$ 列のグリッドがある。このグリッドは円筒状であり、左端と右端が繋がっているため、列 $1$ と列 $W$ は隣接している。

いくつかのマスには皿が置かれており、その一部の皿には豆が置かれている。初期状態では、各皿には豆は高々1つしか置かれていない。ゲームの進行中、1つの皿に任意の数の豆を置くことができるようになる。

AliceとBobは、このグリッド上で交互に豆を動かすゲームを行う。Aliceが先手である。各ターンにおいて、プレイヤーは任意の豆を1つ選び、その現在の行と列を $(r, c)$ とすると、以下のルールに従って豆を移動させることができる。

  • 豆は、皿が置かれているマスにのみ移動できる。
  • 豆は、その特定の豆が過去に存在したことのあるマスには移動できない(すべての豆は区別可能である)。
  • $(r, c)$ にある豆は、以下のいずれかの方向に1マス移動できる。
    • 下へ($(r+1, c)$ へ移動。$r < H$ の場合のみ可能)
    • 右へ($c < W$ ならば $(r, c+1)$ へ、 $c = W$ ならば $(r, 1)$ へ移動)
    • 左へ($c > 1$ ならば $(r, c-1)$ へ、 $c = 1$ ならば $(r, W)$ へ移動)

自分のターンにどの豆も動かせなくなったプレイヤーが負けとなる。 両者が最適に行動すると仮定したとき、どちらが勝つか判定せよ。

入力

入力の最初の行には、2つの整数 $H$ と $W$ ($1 \le H, W \le 1000$) が含まれる。 続いて $H$ 行からなる初期のグリッドの記述が続く。各行は長さ $W$ の文字列である。各行の $j$ 番目の文字は、そのマス $(i, j)$ に皿がない場合は '#'、空の皿がある場合は '.'、豆がちょうど1つ置かれた皿がある場合は 'B' である。グリッドにこれら3種類の文字がすべて含まれているとは限らない(例えば、豆が1つもないグリッドも有効である)。

出力

両者が最適に行動したときにAliceが勝つならば "Alice" と出力せよ。そうでなければ "Bob" と出力せよ。

入出力例

入力 1

2 3
B.#
#..

出力 1

Alice

入力 2

1 1
B

出力 2

Bob

入力 3

1 3
B#.

出力 3

Alice

注記

最初の例では、唯一の豆は初期状態で $(1, 1)$ にある。Aliceはそれを $(1, 2)$ に動かす。Bobの唯一の可能な手は $(2, 2)$ への移動であり、その後Aliceが豆を $(2, 3)$ に動かすとBobは動かせる豆がなくなるため、Aliceの勝ちとなる。

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.