結果

問題 No.13 囲みたい!
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-01 15:59:16
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 61,652 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 14:12:34
合計ジャッジ時間 1,144 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <queue>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int w, h;
int b[110][110];
bool d[110][110];//一度調べた部分を記録
int used[110][110];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

bool bfs(int y, int x, int px, int py, int num){
	d[y][x] = true; used[y][x] = 1;
	rep(i, 4){
		int nowy = y + dy[i], nowx = x + dx[i];
		if(nowy < 0 || h <= nowy || nowx < 0 || w <= nowx) continue;
		if(nowy == py && nowx == px) continue;
		if(b[nowy][nowx] != num) continue;
		if(used[nowy][nowx]){
			return true;
		}
		bfs(nowy, nowx, y, x, num);
	}
	return false;
}

int main(void){
	cin >> w >> h;
	rep(i, h)rep(j, w) cin >> b[i][j];
	rep(i, h)rep(j, w){
		if(d[i][j]) continue;
		rep(a, 110)rep(b, 110) used[a][b] = 0;
		if(bfs(i, j, -1, -1, b[i][j])){
			printf("possible\n");
			return 0;
		}
	}
	printf("impossible\n");
	return 0;
}
0