結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
ゆるく
|
| 提出日時 | 2014-11-09 02:31:59 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 5,000 ms |
| コード長 | 1,188 bytes |
| コンパイル時間 | 289 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2024-10-13 10:38:36 |
| 合計ジャッジ時間 | 1,802 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
w, h = map(int, input().split())
m = [[int(i) for i in input().split()] for i in range(h)]
d = [[0 for _ in range(w)] for _ in range(h)]
dist = ((1,0), (-1,0), (0,1), (0,-1))
def solve(x, y):
q = deque()
q.append((x << 32) + (y << 16) + (0xFF << 8) + 0xFF)
d[y][x] = True
while (q):
v = q.popleft()
vx = v >> 32
vy = (v >> 16) & 0xFF
ox = (v >> 8) & 0xFF
oy = v & 0xFF
for fdist in dist:
ny = vy + fdist[0]
nx = vx + fdist[1]
if nx == ox and ny == oy:
continue
if nx >= w or nx < 0 or ny >= h or ny < 0:
continue
if m[ny][nx] != m[y][x]:
continue
if d[ny][nx]:
return True
d[ny][nx] = True
q.append((nx << 32) + (ny << 16) + (vx << 8) + vy)
return False
flag = False
for y in range(h):
for x in range(w):
if d[y][x]:
continue
if solve(x, y):
flag = True
break
print("possible" if flag else "impossible")
ゆるく