結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-06-19 09:37:47 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 866 bytes | 
| コンパイル時間 | 99 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 11,648 KB | 
| 最終ジャッジ日時 | 2024-10-11 06:20:35 | 
| 合計ジャッジ時間 | 1,483 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 13 RE * 3 | 
ソースコード
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")
            
            
            
        