結果

問題 No.13 囲みたい!
ユーザー w10y26w10y26
提出日時 2017-06-14 09:23:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,295 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 91,832 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-24 23:31:41
合計ジャッジ時間 1,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int w,h;
int field[101][101];
int used[101][101];
bool d[101][101];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool flag = false;

void bfs(int y, int x, int py, int px, 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(field[nowy][nowx] != num) continue;
		if(used[nowy][nowx]){
			flag = true;
			return;
		}
		bfs(nowy, nowx, y, x, num);
	}
	return;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> w >> h;
	rep(i,h)rep(j,w) cin >> field[i][j];

	rep(i,h)rep(j,w){
		if(d[i][j]) continue;
		rep(a,101)rep(b,101) used[a][b] = 0;
		bfs(i, j, -1, -1, field[i][j]);
	}


	cout << ((flag)? "possible":"impossible") << endl;

}
0