結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-06-19 08:44:20 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 867 bytes |
| コンパイル時間 | 120 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-10-11 05:18:25 |
| 合計ジャッジ時間 | 1,498 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 RE * 2 |
ソースコード
import sys
def ok(y, x):
return y >= 0 and x >= 0 and y < H and x < W
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
def dfs(y, x, pre):
check[y][x] = True
for k in range(4):
if pre == k:
continue
ny = y + dy[k]
nx = x + dx[k]
if not ok(ny, nx):
continue
if field[y][x] != field[ny][nx]:
continue
if check[ny][nx]:
return True
if dfs(ny, nx, (k + 2) % 4):
return True
return False
W, H = map(int, input().split())
field = []
for _ in range(H):
field.append(list(map(int, input().split())))
check = [[False for _ in range(W)] for _ in range(H)]
for i in range(H):
for j in range(W):
if check[i][j]:
continue
if dfs(i, j, -1):
print("possible")
sys.exit(0)
print("impossible")