結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-02-10 19:54:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,292 bytes |
| コンパイル時間 | 525 ms |
| コンパイル使用メモリ | 57,948 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:40:48 |
| 合計ジャッジ時間 | 1,182 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cstring>
#include <climits>
#define W_MAX 100
#define H_MAX 100
#define T_USED 10000
using namespace std;
enum Way
{
None = 0,
Right,
Left,
Up,
Down
};
int W, H, M[H_MAX + 2][W_MAX + 2], t[H_MAX + 2][W_MAX + 2];
bool update(int x, int y, int m, Way from)
{
if (M[y][x] == m && t[y][x] >= T_USED)
return true;
else if (M[y][x] == m)
t[y][x] = T_USED;
else
return false;
if (from != Left && update(x - 1, y, m, Right))
return true;
if (from != Right && update(x + 1, y, m, Left))
return true;
if (from != Up && update(x, y - 1, m, Down))
return true;
if (from != Down && update(x, y + 1, m, Up))
return true;
return false;
}
bool calc()
{
for (int y = 1; y <= H; ++y)
for (int x = 1; x <= W; ++x)
if (t[y][x] != T_USED && update(x, y, M[y][x], None))
return true;
return false;
}
int main()
{
cin >> W >> H;
for (int y = 1; y <= H; ++y)
for (int x = 1; x <= W; ++x)
{
cin >> M[y][x];
t[y][x] = 0;
}
for (int y = 0; y <= H + 1; ++y)
{
M[y][0] = M[y][W + 1] = t[y][0] = t[y][W + 1] = 0;
}
for (int x = 0; x <= W + 1; ++x)
{
M[0][x] = M[H + 1][x] = t[0][x] = t[H + 1][x] = 0;
}
if (calc())
cout << "possible" << endl;
else
cout << "impossible" << endl;
return 0;
}