結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-31 11:37:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 953 bytes |
| コンパイル時間 | 290 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,648 KB |
| 最終ジャッジ日時 | 2024-10-09 10:54:12 |
| 合計ジャッジ時間 | 1,589 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 RE * 2 |
ソースコード
import sys
def inner_range(y, x):
return y >= 0 and x >= 0 and y < H and x < W
def check(y, x, py, px):
matrix[y][x] = True
for dy, dx in zip(DY, DX):
ny = y + dy
nx = x + dx
if nx == px and ny == py:
continue
if 0 <= ny < H and 0 <= nx < W and area[y][x] == area[ny][nx]:
if matrix[ny][nx]:
return True
if check(ny, nx, y, x):
return True
return False
W, H = map(int, input().split())
matrix = [[False for _ in range(W)] for _ in range(H)]
DY = (1, 0, -1, 0)
DX = (0, 1, 0, -1)
area = []
for _ in range(H):
area.append(list(map(int, input().split())))
judge = False
for i in range(H):
for j in range(W):
if matrix[i][j]:
continue
if check(i, j, -1, -1):
print("possible")
sys.exit()
print("impossible")