結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  msm1993 | 
| 提出日時 | 2019-04-16 13:10:13 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 1,352 bytes | 
| コンパイル時間 | 1,286 ms | 
| コンパイル使用メモリ | 160,888 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-22 08:13:43 | 
| 合計ジャッジ時間 | 2,055 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
int H, W;
int d[110][110];
bool used[110][110];
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
bool isOutOfRange(int h, int w) {
    return h < 0 || h >= H || w < 0 || w >= W;
};
bool calc(int y, int x, int pre_y, int pre_x) {
    used[y][x] = true;
    bool ret = false;
    rep(i, 4) {
        int nx = x + dx[i], ny = y + dy[i];
        if(isOutOfRange(ny, nx) || d[y][x] != d[ny][nx] || (ny == pre_y && nx == pre_x)) continue;
        if(used[ny][nx]) return true;
        ret |= calc(ny, nx, y, x);
    }
    return ret;
}
int main(){
    cin >> W >> H;
    rep(i, H) rep(j, W) cin >> d[i][j];
    bool f = false;
    rep(i, H) rep(j, W) {
        if(!used[i][j]) f |= calc(i, j, -1, -1);
    }
    string yes = "possible", no = "impossible";
    cout << (f ? yes : no) << endl;
    return 0;
}
            
            
            
        