結果

問題 No.13 囲みたい!
ユーザー krotonkroton
提出日時 2014-10-31 12:54:13
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 985 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 57,644 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-28 23:47:05
合計ジャッジ時間 7,128 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

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

int W, H;
int M[111][111];

bool used[111][111];
bool dfs(int y, int x, int py, int px){
    if(y < 0 || y >= H || x < 0 || x >= W)return false;
    if(M[y][x] != M[py][px])return false;
    if(used[y][x])return true;
    
    used[y][x] = true;
    
    bool res = false;
    for(int k=0;k<4;k++){
        int ny = y + dy[k];
        int nx = x + dx[k];
        if(ny == py && nx == px)continue;
        
        res |= dfs(ny, nx, y, x);
    }
    
    used[y][x] = false;
    return res;
}

int main(){
    cin >> W >> H;
    for(int y=0;y<H;y++)for(int x=0;x<W;x++)cin >> M[y][x];
    
    for(int y=0;y<H;y++)for(int x=0;x<W;x++){
        bool res = dfs(y, x, y, x);
        if(res){
            cout << "possible" << endl;
            return 0;
        }
    }
    
    cout << "impossible" << endl;
    
    return 0;
}
0