結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2016-08-04 14:32:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,073 bytes |
| コンパイル時間 | 519 ms |
| コンパイル使用メモリ | 64,344 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-06 23:50:07 |
| 合計ジャッジ時間 | 1,422 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 1 |
ソースコード
#include<iostream>
#include<set>
using namespace std;
typedef pair<int, int> pii;
int W, H;
int M[100][100];
bool reached[100][100];
bool flag=false;
const pii dd[]={{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool is(int h, int w){
return (0<=h&&h<H&&0<=w&&w<W);
}
void dfs(int h, int w, int ph, int pw){
if(flag) return;
reached[h][w]=true;
for(auto d: dd){
auto nh=h+d.first;
auto nw=w+d.second;
if(!is(nh, nw)) continue;
if(nh==ph&&nw==pw) continue;
if(M[h][w]!=M[nh][nw]) continue;
if(reached[nh][nw]){
flag=true;
return;
}
dfs(nh, nw, h, w);
}
return;
}
int main(){
cin>> W>> H;
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
cin>> M[i][j];
}
}
set<int> st;
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
if(st.count(M[i][j])==1) continue;
dfs(i, j, -1, -1);
st.insert(M[i][j]);
}
}
cout<< (flag? "possible": "impossible")<< endl;
return 0;
}
ikd