結果

問題 No.13 囲みたい!
ユーザー maimai
提出日時 2017-03-17 00:41:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 779 bytes
コンパイル時間 1,434 ms
コンパイル使用メモリ 165,612 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 05:26:15
合計ジャッジ時間 2,271 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 (sgn[y][x]==step) return ;
    else 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);
      }
    }
  }
  cout<<"impossible"<<endl;
  
  return 0;
}
0