結果
問題 | No.13 囲みたい! |
ユーザー |
![]() |
提出日時 | 2022-02-17 12:05:52 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 756 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-06-29 07:37:31 |
合計ジャッジ時間 | 1,227 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 RE * 3 |
ソースコード
# InputW, H = map(int, input().split())A = [ list(map(int, input().split())) for i in range(H) ]# DFS Functiondef dfs(x, y, A, vis):dx = [ 1, 0, -1, 0 ]dy = [ 0, 1, 0, -1 ]vis[x][y] = Truecnts = (1, 0)for i in range(4):tx, ty = x + dx[i], y + dy[i]if 0 <= tx and tx < H and 0 <= ty and ty < W and A[tx][ty] == A[x][y]:if not vis[tx][ty]:res = dfs(tx, ty, A, vis)cnts = (cnts[0] + res[0], cnts[1] + res[1])cnts = (cnts[0], cnts[1] + 1)return cnts# DFSvis = [ [ False ] * W for i in range(H) ]answer = Falsefor i in range(H):for j in range(W):if not vis[i][j]:res = dfs(i, j, A, vis)if res[1] // 2 != res[0] - 1:answer = True# Outputif answer:print("possible")else:print("impossible")