結果
問題 |
No.13 囲みたい!
|
ユーザー |
![]() |
提出日時 | 2023-03-02 18:00:45 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 43 ms / 5,000 ms |
コード長 | 1,228 bytes |
コンパイル時間 | 201 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2024-09-17 12:10:47 |
合計ジャッジ時間 | 1,333 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
import sys import threading # threading.stack_size(4096 * 1024 * 16) sys.setrecursionlimit(100000) w, h = map(int, input().split()) a = [[*map(int, input().split())] for _ in range(h)] INF = 10**9 visit = [[False for i in range(w)] for j in range(h)] dist = [[INF for i in range(w)] for j in range(h)] dy = [-1, 0, 1, 0] dx = [0, 1, 0, -1] cnt = 0 def dfs(now, pre, num): ret = False d = dist[now[0]][now[1]] for i in range(4): y2 = now[0] + dy[i] x2 = now[1] + dx[i] if y2 < 0 or y2 > h-1 or x2 < 0 or x2 > w-1: continue if not a[y2][x2] == num or [y2, x2] == pre: continue if dist[y2][x2] == INF: dist[y2][x2] = d + 1 ret = dfs([y2, x2], now, num) if ret: return ret elif d >= 3: return True return ret def solve(): ret = False for i in range(h): for j in range(w): if dist[i][j] == INF: dist[i][j] = 0 ret = dfs([i, j], [-1, -1], a[i][j]) if ret: print("possible") return print("impossible") # threading.Thread(target=solve).start() solve()