結果
問題 |
No.13 囲みたい!
|
ユーザー |
|
提出日時 | 2021-02-19 22:49:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,038 bytes |
コンパイル時間 | 2,035 ms |
コンパイル使用メモリ | 190,980 KB |
最終ジャッジ日時 | 2025-01-19 01:07:59 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#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; 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; if (dfs(y2, x2, y, x)) return true; } vis[y][x] = 1; return false; } 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; }