結果

問題 No.13 囲みたい!
ユーザー maimai
提出日時 2017-03-17 07:44:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 783 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 165,716 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 18:52:14
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 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,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int mat[111][111];
int w,h;

void yes(){
  cout<<"possible"<<endl;
  exit(0);
}

int sgn[111][111];
int seen;
int lstep=0;
void dfs(int y,int x,int step){
  if (y<0||x<0||h<=y||w<=x) return ;
  if (mat[y][x]!=seen) return ;
  if (sgn[y][x]!=0){
    if (abs(sgn[y][x]-step)<=1) return ;
    yes();
  }
  sgn[y][x]=++step;
  lstep=max(lstep,step);
  dfs(y-1,x,step);
  dfs(y+1,x,step);
  dfs(y,x-1,step);
  dfs(y,x+1,step);
  return ;
}

int main(){
  cin>>w>>h;
  for(int y=0;y<h;++y){
    for(int x=0;x<w;++x){
      scanf("%d",&(mat[y][x]));
    }}

  int t=0;
  for(int y=0;y<h;++y){
    for(int x=0;x<w;++x){
      if(sgn[y][x]==0){
	seen=mat[y][x];
	dfs(y,x,lstep+1);
      }
    }
  }
  cout<<"impossible"<<endl;
  
  return 0;
}
0