結果

問題 No.13 囲みたい!
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 06:06:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,086 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 54,844 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:14:50
合計ジャッジ時間 1,034 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |     scanf("%d %d", &W, &H);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:33:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |             scanf("%d", &M[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>

int W, H;
int M[100][100];
bool used[100][100];

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

int dfs(int x, int y, int prev, int type){
    used[y][x] = true;

    bool f = false;
    for(int i=0;i<4;i++){
        if(i == 3-prev){continue;}

        int nx = x + dx[i], ny = y + dy[i];
        if(0 <= nx && nx < W && 
           0 <= ny && ny < H && M[ny][nx] == type){
            if(used[ny][nx]){return true;}
            f = f || dfs(nx, ny, i, type);
        }
    }

    return f;
}

int main(){
    scanf("%d %d", &W, &H);
   
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            scanf("%d", &M[i][j]);
        }
    }

    std::fill(&used[0][0], &used[0][0]+100*100, false);
    
    bool can = false;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(!used[i][j]){
                can = can || dfs(j, i, -1, M[i][j]);
            }
        }
    }

    if(can){
        puts("possible");
    }else{
        puts("impossible");
    }
}
0