結果

問題 No.13 囲みたい!
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-01 16:31:16
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 62,208 KB
実行使用メモリ 814,848 KB
最終ジャッジ日時 2024-04-27 14:14:24
合計ジャッジ時間 3,363 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 flag = false;
int goaly, goalx;
void bfs(int y, int x, int py, int px, int num){
	// printf("%d %d %d %d %d\n", y, x, py, px, 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(nowy == goaly && nowx == goalx){
			flag = true;
			return;
		}
		bfs(nowy, nowx, y, x, num);
	}
	return;
}

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;
		goaly = i; goalx = j;
		bfs(i, j, -1, -1, b[i][j]);
	}
	if(flag) printf("possible\n");
	else printf("impossible\n");
	return 0;
}
0