結果
問題 | No.13 囲みたい! |
ユーザー | szkhts |
提出日時 | 2022-06-19 09:40:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 61 ms / 5,000 ms |
コード長 | 907 bytes |
コンパイル時間 | 90 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 15,104 KB |
最終ジャッジ日時 | 2024-10-11 06:23:46 |
合計ジャッジ時間 | 1,438 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
import sys sys.setrecursionlimit(12000) W, H = map(int, input().split()) field = [] for _ in range(H): field.append(list(map(int, input().split()))) def ok(x, y): return y >= 0 and x >= 0 and x < H and y < W def dfs(x, y): dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] visit[x][y] = True c = (1, 0) for k in range(4): ny = y + dy[k] nx = x + dx[k] if ok(nx, ny) and field[nx][ny] == field[x][y]: if not visit[nx][ny]: res = dfs(nx, ny) c = (c[0] + res[0], c[1] + res[1]) c = (c[0], c[1] + 1) return c visit = [[False for _ in range(W)] for _ in range(H)] ans = False for i in range(H): for j in range(W): if not visit[i][j]: res = dfs(i, j) if res[1] // 2 != res[0] - 1: ans = True if ans: print("possible") else: print("impossible")