結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
古寺いろは
|
| 提出日時 | 2015-04-16 00:12:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 895 bytes |
| コンパイル時間 | 1,157 ms |
| コンパイル使用メモリ | 158,040 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:43:07 |
| 合計ジャッジ時間 | 1,757 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
int H, W;
int board[100][100];
bool check[100][100];
bool ok(int y, int x){
return y >= 0 && x >= 0 && y < H && x < W;
}
int dy[] = {1, 0, -1, 0};
int dx[] = { 0, 1, 0, -1 };
bool dfs(int y, int x, int pre){
check[y][x] = true;
for (int k = 0; k < 4; k++)
{
if (pre == k) continue;
int ny = y + dy[k];
int nx = x + dx[k];
if (!ok(ny, nx)) continue;
if (board[y][x] != board[ny][nx]) continue;
if (check[ny][nx]) return true;
if (dfs(ny, nx, (k + 2) % 4)) return true;
}
return false;
}
int main() {
cin >> W >> H;
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
cin >> board[i][j];
}
}
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
if (check[i][j]) continue;
if (dfs(i, j, -1)){
cout << "possible" << endl;
return 0;
}
}
}
cout << "impossible" << endl;
}
古寺いろは