結果

問題 No.13 囲みたい!
ユーザー A8pfA8pf
提出日時 2018-10-05 12:50:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,506 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 65,484 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 16:43:03
合計ジャッジ時間 1,282 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <string.h>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

int m[100][100];
int w,h;
int dfs(int n,int x,int y,int sx,int sy,bool check[][100],int cnt)
{
	bool cc[100][100];
	memcpy(cc,check,sizeof(bool)*10000);
	check[y][x]=true;
	if(cnt>1)
		check[sy][sx]=false;
	if(x<w-1 && m[y][x+1]==n && !check[y][x+1])
	{
		if(x+1==sx && y==sy)
			return 1;
		else
			return dfs(n,x+1,y,sx,sy,check,cnt+1);
	}
	if(x>0 && m[y][x-1]==n && !check[y][x-1])
	{
		if(x-1==sx && y==sy)
			return 1;
		else
			return dfs(n,x-1,y,sx,sy,check,cnt+1);
	}
	if(y<h-1 && m[y+1][x]==n && !check[y+1][x])
	{
		if(x==sx && y+1==sy)
			return 1;
		else
			return dfs(n,x,y+1,sx,sy,check,cnt+1);
	}
	if(y<h+1 && m[y-1][x]==n && !check[y-1][x])
	{
		if(x==sx && y-1==sy)
			return 1;
		else
			return dfs(n,x,y-1,sx,sy,check,cnt+1);
	}
	return 0;
}

int main()
{
	int ans=0;
	cin>>w>>h;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			cin>>m[i][j];
	}

	//それぞれの数字について探索する
	for(int n=1;n<1001;n++)
	{
		bool check[100][100];
		//fill(check[0],check[100],false);
		//始点を探索する
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(m[i][j]==n)
				{
					fill(check[0],check[100],false);
					ans+=dfs(n,j,i,j,i,check,0);
				}
				if(ans>0)
				{
					cout<<"possible"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"impossible"<<endl;
	return 0;
}
0