結果

問題 No.13 囲みたい!
ユーザー latte0119latte0119
提出日時 2016-02-24 21:37:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 386 ms / 5,000 ms
コード長 1,210 bytes
コンパイル時間 1,115 ms
コンパイル使用メモリ 159,180 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:22:53
合計ジャッジ時間 2,128 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int W,H;
int A[111][111];
bool used[111][111];

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

bool dfs(int y,int x,int p){
    used[y][x]=true;
    rep(i,4){
        int ny=y+dy[i],nx=x+dx[i];
        if(ny<0||ny>=H||nx<0||nx>=W||A[ny][nx]!=A[y][x]||p==ny*W+nx)continue;
        if(used[ny][nx])return true;
        if(dfs(ny,nx,y*W+x))return true;
    }
    return false;
}

signed main(){
    cin>>W>>H;
    rep(i,H)rep(j,W)cin>>A[i][j];

    rep(i,H)rep(j,W){
        memset(used,0,sizeof(used));
        if(dfs(i,j,-1)){
            cout<<"possible"<<endl;
            return 0;
        }
    }
    cout<<"impossible"<<endl;
    return 0;
}
0