結果

問題 No.13 囲みたい!
ユーザー otamay6otamay6
提出日時 2019-10-18 01:15:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 709 ms / 5,000 ms
コード長 1,021 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 173,396 KB
実行使用メモリ 4,632 KB
最終ジャッジ日時 2023-09-07 18:57:08
合計ジャッジ時間 3,815 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int W,H;cin>>W>>H;
    vector<vector<int>> M(W,vector<int>(H));
    REP(i,H) REP(j,W) cin>>M[j][i];
    int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    vector<vector<bool>> used(W,vector<bool>(H,false));
    auto dfs=[&](auto &&f,int x,int y,int px,int py)->bool{
        used[x][y]=true;
        bool ret=false;
        REP(i,4){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0||W<=nx||ny<0||H<=ny||(nx==px&&ny==py)||M[nx][ny]!=M[x][y]) continue;
            if(used[nx][ny]) return true;
            if(f(f,nx,ny,x,y)){
                ret=true;
                break;
            }
        }
        used[x][y]=false;
        return ret;
    };
    bool ans=false;
    REP(i,H) REP(j,W) ans=ans|dfs(dfs,j,i,j,i);
    if(ans) cout<<"possible"<<endl;
    else cout<<"impossible"<<endl;
}
0