結果

問題 No.13 囲みたい!
ユーザー btkbtk
提出日時 2015-05-03 21:13:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,581 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 97,460 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-19 05:22:18
合計ジャッジ時間 1,762 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> PP;
int H, W;
int M[110][110];
vector<list<P>> cd;
#define mp(a,b,c,d) make_pair( make_pair((a),(b)),make_pair((c),(d)) )

#define dir(xx,yy,x,y,i)(xx)=(x)+dir[(i)],(yy)=(y)+dir[(i)+1];

const int dir[] = { 0, 1, 0, -1, 0 };


bool bfs(int c){
	cout << c << endl;
	queue<PP> que;
	for (auto &u : cd[c])
	if(M[u.first][u.second]==c){
		que.push(mp(u.first, u.second, -1, -1));
		M[u.first][u.second] *= -1;
		while (que.empty() == false){
			auto v = que.front(); que.pop();
			for (int i = 0; i < 4; i++){
				int xx, yy;
				dir(xx, yy, v.first.first, v.first.second, i);
				if ((xx != v.second.first) || (yy != v.second.second)){
					if (M[xx][yy] == -c){
						return true;
					}
					if (M[xx][yy] == c){
						M[xx][yy] *= -1;
						que.push(mp(xx, yy, v.first.first, v.first.second));
					}
				}
			}
		}
	}
	return false;
}



int main(void){
	cd.resize(1010);
	cin >> W >> H;
	for (int i = 1; i <=H; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			cin >> M[i][j];
			cd[M[i][j]].push_back(make_pair(i, j));
		}
	}

	for (int i = 1; i <= 1000; i++)
		if (cd[i].size() >= 4)
			if (bfs(i))
			{
				
				cout << "possible" << endl;
				return 0;
			}
	cout << "impossible" << endl;
	return 0;
}
0