結果
| 問題 | No.13 囲みたい! |
| コンテスト | |
| ユーザー |
w10y26
|
| 提出日時 | 2017-06-14 09:18:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,313 bytes |
| コンパイル時間 | 926 ms |
| コンパイル使用メモリ | 93,068 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 18:23:42 |
| 合計ジャッジ時間 | 1,834 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 2 |
ソースコード
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
int w,h;
int field[101][101];
int used[101][101];
bool d[101][101];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool flag = false;
bool bfs(int y, int x, int py, int px, int num){
d[y][x] = true; used[y][x] = 1;
rep(i, 4){
int nowy = y + dy[i], nowx = x + dx[i];
if(nowy < 0 || h <= nowy || nowx <0 || w <= nowx) continue;
//戻るの禁止
if(nowy == py && nowx == px) continue;
//違う番号なら
if(field[nowy][nowx] != num) continue;
if(used[nowy][nowx]) return true;
bfs(nowy, nowx, y, x, num);
}
return false;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> w >> h;
rep(i,h)rep(j,w) cin >> field[i][j];
rep(i,h)rep(j,w){
if(d[i][j]) continue;
rep(a,101)rep(b,101) used[a][b] = 0;
if(bfs(i, j, -1, -1, field[i][j])){
flag = true;
break;
}
}
cout << ((flag)? "possible":"impossible") << endl;
}
w10y26