結果

問題 No.13 囲みたい!
ユーザー square1001square1001
提出日時 2022-02-17 12:05:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 756 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 9,148 KB
最終ジャッジ日時 2023-09-11 17:37:29
合計ジャッジ時間 1,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,188 KB
testcase_01 AC 16 ms
8,180 KB
testcase_02 AC 16 ms
8,200 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 32 ms
8,600 KB
testcase_07 AC 32 ms
8,676 KB
testcase_08 AC 31 ms
8,548 KB
testcase_09 AC 32 ms
8,596 KB
testcase_10 AC 19 ms
8,264 KB
testcase_11 AC 29 ms
8,268 KB
testcase_12 AC 17 ms
8,268 KB
testcase_13 AC 21 ms
8,364 KB
testcase_14 AC 22 ms
8,348 KB
testcase_15 AC 16 ms
8,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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")
0