結果

問題 No.233 めぐるはめぐる (3)
ユーザー むらためむらため
提出日時 2019-01-29 02:09:41
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 881 bytes
コンパイル時間 2,381 ms
コンパイル使用メモリ 67,532 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 03:09:07
合計ジャッジ時間 7,450 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord
const dxdy4 :seq[tuple[x,y:int]] = @[(0,1),(1,0),(0,-1),(-1,0)]

let w = scan()
let h = scan()
var M = newSeqWith(w,newSeqUninitialized[int](h))
for y in 0..<h:
  for x in 0..<w:
    M[x][y] = scan()

var already = newSeqWith(w,newSeq[bool](h))
proc dfs(x,y,px,py,m:int) =
  already[x][y] = true
  for d in dxdy4:
    let nx = x + d.x
    let ny = y + d.y
    if nx < 0 or ny < 0 or nx >= w or ny >= h : continue
    if nx == px and ny == py : continue
    if M[nx][ny] != m : continue
    if already[nx][ny] : quit "possible",0
    dfs(nx,ny,x,y,m)

for x in 0..<w:
  for y in 0..<h:
    if not already[x][y] : dfs(x,y,-1,-1,M[x][y])
echo "impossible"
0