結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
w10y26
|
| 提出日時 | 2017-06-14 09:23:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 5,000 ms |
| コード長 | 1,295 bytes |
| コンパイル時間 | 960 ms |
| コンパイル使用メモリ | 91,876 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 18:34:29 |
| 合計ジャッジ時間 | 1,686 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#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;
void 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]){
flag = true;
return;
}
bfs(nowy, nowx, y, x, num);
}
return;
}
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;
bfs(i, j, -1, -1, field[i][j]);
}
cout << ((flag)? "possible":"impossible") << endl;
}
w10y26