結果

問題 No.13 囲みたい!
ユーザー TwizzTwizz
提出日時 2017-05-18 11:37:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 851 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 159,836 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 23:07:54
合計ジャッジ時間 2,043 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll mod = 10000000000;

int h, w;
int m[102][102] = {};
int flag[102][102] = {};
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

bool dfs(int y, int x, int pre) {
	flag[y][x] = 1;
	rep(k, 0, 4) {
		int nx = x + dx[k];
		int ny = y + dy[k];
		if (pre == k)continue;
		if (!(nx >= 0 && nx < w&&ny >= 0 && ny < h))continue;
		if (m[ny][nx] != m[y][x])continue;
		if (flag[ny][nx])return 1;
		if (dfs(ny, nx, (k + 2) % 4))return 1;
	}
	return 0;
}

int main() {
	cin >> h >> w;
	rep(j, 0, h) {
		rep(i, 0, w) {
			cin >> m[i][j];
		}
	}
	bool f = 0;
	rep(j, 0, h) {
		rep(i, 0, w) {
			if (dfs(i, j, 0)) {
				print("possible");
				return 0;
			}
		}
	}
	print("impossible"); 
}
0