結果

問題 No.13 囲みたい!
ユーザー goodbatongoodbaton
提出日時 2015-07-18 12:09:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,338 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 72,076 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:19:14
合計ジャッジ時間 1,234 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define MAX_L 5000000
#define SIZE 100001


int w,h;
int m[100][100];
int mo[5]={0,1,0,-1,0};
bool visit[100][100]={0};

bool dfs(int y,int x,int by,int bx){
    
    if(y<0 || x<0 || h<=y || w<=x) return false;
    
    if(visit[y][x]==true) return true;
    
    visit[y][x]=true;
    
    for(int i=0;i<4;i++){
        if(y+mo[i]==by && x+mo[i+1]==bx) continue;
        
        if(m[y][x]==m[y+mo[i]][x+mo[i+1]])
            if(dfs(y+mo[i],x+mo[i+1],y,x)){
                return true;
            }
    }
    
    return false;
}

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]);
        }
    }
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(visit[i][j]==false){
                if(dfs(i,j,-1,-1)){
                    puts("possible");
                    return 0;
                }
            }
            
        }
    }
    
    puts("impossible");
    return 0;
}
0