結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  square1001 | 
| 提出日時 | 2022-02-17 12:06:16 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 51 ms / 5,000 ms | 
| コード長 | 797 bytes | 
| コンパイル時間 | 80 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 15,616 KB | 
| 最終ジャッジ日時 | 2024-06-29 07:37:36 | 
| 合計ジャッジ時間 | 1,217 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
import sys
sys.setrecursionlimit(12000)
# Input
W, H = map(int, input().split())
A = [ list(map(int, input().split())) for i in range(H) ]
# DFS Function
def dfs(x, y, A, vis):
	dx = [ 1, 0, -1, 0 ]
	dy = [ 0, 1, 0, -1 ]
	vis[x][y] = True
	cnts = (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
	
# DFS
vis = [ [ False ] * W for i in range(H) ]
answer = False
for 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
# Output
if answer:
	print("possible")
else:
	print("impossible")
            
            
            
        