結果

問題 No.13 囲みたい!
ユーザー btkbtk
提出日時 2015-05-03 20:52:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,510 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 95,812 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-19 05:22:02
合計ジャッジ時間 3,293 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,380 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, int x, int y){
	queue<PP> que;
	que.push(mp(x,y,-1,-1));
	M[x][y] *= -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() >= 4u)
			if (bfs(i, cd[i].front().first, cd[i].front().second))
			{
				cout << "possible" << endl;
				return 0;
			}
	cout << "impossible" << endl;
	return 0;
}
0