結果
問題 | No.13 囲みたい! |
ユーザー |
|
提出日時 | 2017-03-17 07:44:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 1,518 ms |
コンパイル使用メモリ | 166,540 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-04 13:17:02 |
合計ジャッジ時間 | 2,316 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#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; }