結果

問題 No.13 囲みたい!
ユーザー kenken714kenken714
提出日時 2019-04-18 22:20:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 747 ms / 5,000 ms
コード長 1,297 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 82,080 KB
実行使用メモリ 4,872 KB
最終ジャッジ日時 2023-10-23 16:25:51
合計ジャッジ時間 2,491 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll h, w, s[110][110];
bool used[110][110];

ll v1[4] = { 0,0,1,-1 }, v2[4] = { 1,-1,0,0 };
bool dfs(ll a, ll b, ll aa, ll bb, ll df) {
	used[a][b] = true;
	REP(i, 4) {
		ll x = a + v1[i], y = b + v2[i];
		if (x >= 0 and x < h and y >= 0 and y < w) {
			if (x == aa and y == bb and df >= 4)return true;
			if (!used[x][y] and s[aa][bb] == s[x][y]) {
				if (dfs(x, y, aa, bb, df + 1))return true;
			}
		}
	}
	return false;
}
int main() {
	cin >> w >> h;
	REP(i, h)REP(j, w)cin >> s[i][j];
	REP(i, h) {
		REP(j, w) {
			REP(ii, 100)REP(jj, 110)used[ii][jj] = false;
			if (dfs(i, j, i, j, 1)) {
				cout << "possible" << endl;
				return 0;
			}
		}
	}
	cout << "impossible" << endl;
}



0