結果

問題 No.13 囲みたい!
ユーザー むらためむらため
提出日時 2017-08-01 04:43:18
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,249 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 69,864 KB
最終ジャッジ日時 2024-04-27 02:28:35
合計ジャッジ時間 1,319 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 50) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 62) Error: cannot open file: queues

ソースコード

diff #

import sequtils,strutils,strscans,algorithm,math,future,sets,queues,tables
template get*():string = stdin.readLine()
template times*(n:int,body:untyped): untyped = (for _ in 0..<n: body)
template `max=`*(x,y:typed):void = x = max(x,y)
template `min=`*(x,y:typed):void = x = min(x,y)


var W,H = 0
(W,H) = get().split().map(parseInt)
var stagesyx = newSeqWith(H,get().split().map(parseInt))
var stages = newSeqWith(W,newSeqWith(H,0))
for y,ys in stagesyx: (for x,xs in ys:stages[x][y] = stagesyx[y][x])
var colors = newSeqWith(W,newSeqWith(H,0))
var currentColor = 0 # currentColor

for x in 0..<W:
  for y in 0..<H:
    if colors[x][y] != 0: continue
    currentColor += 1
    let num = stages[x][y]
    proc dfs(x,y,prex,prey: int) :void =
      colors[x][y] = currentColor
      for d in [(1,0),(0,1),(-1,0),(0,-1)]:
        let (dx,dy) = d
        let (nx,ny) = (x+dx,y+dy)
        if nx >= W or ny >= H or
            nx < 0  or ny < 0 : continue
        if nx == prex and ny == prey : continue
        if stages[nx][ny] != num: continue
        if colors[nx][ny] != currentColor:
          colors[nx][ny] = currentColor
          dfs(nx,ny,x,y)
        else:
          echo "possible"
          quit()
    dfs(x,y,-1,-1)
echo "impossible"





0