QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#18968. ピクセル 8

Statistics

0 と 1 からなる $n \times m$ の行列が、ピクセル画像を表しています。この画像が数字の「8」を形作っているか判定してください。

次の二つの条件を両方満たすとき、かつそのときに限り、この画像は数字の「8」を表すとみなします:

  1. 値が 1 のすべてのピクセルが、ちょうど一つの四近傍連結成分を形成する。

  2. この 1 の連結成分の内部に、ちょうど二つの「穴」が存在する。

    ここで、「穴」とは次の条件を満たす 0 の四近傍連結成分です:

    • この連結成分は 1 に完全に囲まれ(つまり、外側の隣接ピクセルはすべて 1 であり)、行列の境界に一切接していない。

注記: 二つのピクセルが四近傍の意味で隣接するのは、上下左右のいずれかの方向に隣り合っているとき、かつそのときに限ります。

入力

最初の行には二つの正整数 $n,m$ $(1\le n,m\le 1000)$ が含まれます。

続く $n$ 行にはそれぞれ値が 0 または 1 の整数が $m$ 個含まれ、この行列を表します。

出力

この行列が「8」であれば、一行に文字列 "This is eight." を出力してください(引用符は含めません)。

この行列が「8」でなければ、一行に文字列 "I don't know what this number is." を出力してください(引用符は含めません)。

入出力例

入力 1

9 5
0 1 1 1 0
1 1 0 1 1
1 0 0 0 1
1 1 0 1 1
0 1 1 1 0
1 1 0 1 1
1 0 0 0 1
1 1 0 1 1
0 1 1 1 0

出力 1

This is eight.

入力 2

5 3
1 1 1
1 0 1
0 1 0
1 0 1
1 1 1

出力 2

I don't know what this number is.

入力 3

7 7
1 1 1 1 1 1 1
1 0 0 0 0 0 1
1 0 1 1 1 0 1
1 0 1 0 1 1 1
1 0 1 1 1 0 1
1 0 0 0 0 0 1
1 1 1 1 1 1 1

出力 3

This is eight.

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.