問題一覧 > 通常問題

No.13 囲みたい!

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 264
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 37 / 自分の提出
問題文最終更新日: 2026-06-25 15:05:21
I Want to Enclose!
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 13 (順位表) の他の問題:

Problem Statement

kevin is playing a certain game.
You are given a field consisting of cells, \(W\) wide and \(H\) tall.
You first select a cell, then you can trace only through the same number in the up, down, left and right directions, and you can release at any location.
In this game, you get a high score if you can form an enclosure by tracing only through the same number.

An enclosure means that a \(K( \geq 4)\)-sided polygon is formed when lines are drawn connecting the traced cells in the order they were traced.

Given the field, determine whether an enclosure can be formed.
Output \(possible\) if an enclosure can be formed, and \(impossible\) otherwise.

Input

\(W\ H\)
\(M_{11}\ \dots\ M_{i1}\ \dots\ M_{W1}\)
\(M_{12}\ \dots\ M_{i2}\ \dots\ M_{W2}\)
\(\dots\)
\(M_{1j}\ \dots\ M_{ij}\ \dots\ M_{Wj}\)
\(\dots\)
\(M_{1H}\ \dots\ M_{iH}\ \dots\ M_{WH}\)

Line \(1\) contains the numbers \(W\ (1 \leq W \leq 100) \), representing the width, and \(H\ (1 \leq H \leq 100)\), representing the height, separated by a single-byte space.
From line \(2\) onward, each line contains the numbers \(M_{ij}\ (1 \leq M_{ij} \leq 1000)\), representing column \(i\) of row \(j\), separated by single-byte spaces.

Output

Output possible or impossible.
Print a newline at the end.

Sample

Sample 1
Input
3 3
1 2 3
1 1 3
1 1 4
Output
possible

By tracing \(1\) appropriately in the lower left, a 4-sided polygon can be formed.

Sample 2
Input
5 4
1 2 2 2 3
2 2 4 2 2
2 1 1 1 2
2 2 2 2 2
Output
possible

With \(2\), an 8-sided polygon shaped like the character 凸 is formed.

Sample 3
Input
5 4
5 5 5 3 5
5 3 1 5 1
5 2 2 5 8
5 5 5 5 9
Output
impossible

No enclosure can be formed in this field.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。