結果

問題 No.13 囲みたい!
ユーザー T1610T1610
提出日時 2019-03-22 21:05:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,352 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 168,484 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 06:15:08
合計ジャッジ時間 2,466 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0