結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-04-18 22:20:13 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 507 ms / 5,000 ms | 
| コード長 | 1,297 bytes | 
| コンパイル時間 | 647 ms | 
| コンパイル使用メモリ | 81,168 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-22 10:45:59 | 
| 合計ジャッジ時間 | 2,045 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
#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;
}
            
            
            
        