結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-19 22:41:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,049 bytes |
| コンパイル時間 | 1,815 ms |
| コンパイル使用メモリ | 192,800 KB |
| 最終ジャッジ日時 | 2025-01-19 00:57:10 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 TLE * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
int w, h;
int bd[128][128];
int vis[128][128];
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
bool dfs(int y, int x, int py, int px) {
if (vis[y][x] == -1) {
return true;
}
vis[y][x] = -1;
bool ret = false;
for (int k = 0; k < 4; k++) {
int y2 = y + dy[k];
int x2 = x + dx[k];
if (x2 < 0 || x2 >= w) continue;
if (y2 < 0 || y2 >= h) continue;
if (y2 == py && x2 == px) continue;
if (bd[y2][x2] != bd[y][x]) continue;
ret |= dfs(y2, x2, y, x);
}
vis[y][x] = 1;
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> w >> h;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> bd[i][j];
bool ck = false;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (vis[i][j]) continue;
ck |= dfs(i, j, -1, -1);
}
}
if (ck)
cout << "possible" << endl;
else
cout << "impossible" << endl;
return 0;
}