結果

問題 No.13 囲みたい!
ユーザー fiordfiord
提出日時 2015-07-12 23:19:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 811 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 157,944 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:19:08
合計ジャッジ時間 2,217 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int w,h;
int m[100][100];
int mx[]={1,0,0,-1};
int my[]={0,1,-1,0};
bool check(int x,int y,int xx,int yy){
	if(0>x+xx||x+xx>=w)	return false;
	if(0>y+yy||y+yy>=h)	return false;
	return true;
}
bool dfs(int x,int y,int course){
	m[x][y]*=-1;
	for(int i=0;i<4;i++){
		if((i^course)==3)	continue;
		if(check(x,y,mx[i],my[i])){
			if(m[x][y]==m[x+mx[i]][y+my[i]])	return true;
			if(m[x][y]*-1!=m[x+mx[i]][y+my[i]])	continue;
			if(dfs(x+mx[i],y+my[i],i))	return true;
		}
	}
	return false;
}
	
int main(){
	cin>>w>>h;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)	cin>>m[j][i];
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(m[j][i]>0){
				if(dfs(j,i,4)){
					cout<<"possible"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"impossible"<<endl;
	return 0;
}
0