結果

問題 No.13 囲みたい!
ユーザー h_nosonh_noson
提出日時 2016-06-19 15:24:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,406 bytes
コンパイル時間 662 ms
コンパイル使用メモリ 72,048 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 13:00:06
合計ジャッジ時間 1,115 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)

typedef long long ll;

int m[100][100];
bool used[100][100];

int main(void) {
    int i, j, w, h;
    cin >> w >> h;
    rep (i,h) rep (j,w) cin >> m[i][j];

    bool ans = false;
    rep (i,h) rep (j,w) if (!used[i][j]) {
        int x = m[i][j];
        queue<pair<int,int>> q;
        q.push(make_pair(i,j));
        while (!q.empty()) {
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            int dxy[] = {1,0,-1,0};
            int k, cnt = 0;
            rep (k,4) {
                int ny = y + dxy[k];
                int nx = x + dxy[(k+1)%4];
                if (ny < 0 || ny >= h || nx < 0 || ny >= w || x != m[ny][nx]) continue;
                if (used[ny][nx]) {
                    cnt++;
                    continue;
                }
                used[ny][nx] = true;
                q.push(make_pair(ny,nx));
            }
            if (cnt > 1)
                ans = true;
        }
    }
    if (ans)
        cout << "possible" << endl;
    else
        cout << "impossible" << endl;
    return 0;
}
0