結果

問題 No.13 囲みたい!
ユーザー opqopq_opqopq_
提出日時 2015-05-13 17:01:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 954 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 26,428 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 07:33:06
合計ジャッジ時間 1,143 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 3 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
using namespace std;

#define W_MAX 100
#define H_MAX 100

int W, H;
int field[H_MAX][W_MAX];
bool used[H_MAX][W_MAX];
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, 1, 0, -1};

bool dfs(int y, int x, const int& M) {
	used[y][x] = 1;
	int cnt = 0;
	for (int i = 0; i < 4; i++) {
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
		if (used[ny][nx] || field[ny][nx] != M) {
			if (field[ny][nx] == M) if (++cnt) return 1;
			continue;
		}
		if (dfs(ny, nx, M)) return 1;
	}
	return 0;
}

int main() {
	scanf("%d%d", &W, &H);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			scanf("%d", &field[i][j]);
		}
	}
	
	bool f = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (used[i][j]) continue;
			if (dfs(i, j, field[i][j])) {
				f = 1;
				break;
			}
		}
		if (f) break;
	}
	
	printf("%s\n", f ? "possible" : "impossible");
	
	return 0;
}

0