結果

問題 No.13 囲みたい!
ユーザー takakintakakin
提出日時 2020-05-24 15:58:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 917 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-20 01:09:53
合計ジャッジ時間 7,000 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 68 ms
12,288 KB
testcase_04 AC 85 ms
13,312 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
w,h=map(int,input().split())
n=w*h
edge=[[] for _ in range(n)]
M=[[int(i) for i in input().split()] for _ in range(h)]
d=((1,0),(0,1),(-1,0),(0,-1))
E=[0]*1001
for i in range(n):
  ix,iy=i//w,i%w
  for dx,dy in d:
    if 0<=ix+dx<h and 0<=iy+dy<w:
      if M[ix][iy]==M[ix+dx][iy+dy]:
        edge[i].append((ix+dx)*w+(iy+dy))
        E[M[ix][iy]]+=1
ans=False
for i in range(n):
  ix,iy=i//w,i%w
  if E[M[ix][iy]]<8 or len(edge[i])<2:
    continue
  else:
    Chk=[False]*n
    Prev=[None]*n
    Chk[i]=True
    S=[]
    S.append(i)
    while S:
      s=S.pop()
      for g in edge[s]:
        if Chk[g] and g!=Prev[s]:
          ans=True
          break
        elif not Chk[g]:
          Prev[g]=s
          S.append(g)
          Chk[g]=True
        else:
          continue
  if ans==True:
    break
if ans:
  print("possible")
else:
  print("impossible")
  
0