結果

問題 No.13 囲みたい!
ユーザー むらためむらため
提出日時 2019-01-29 02:09:45
言語 Nim
(2.0.2)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 881 bytes
コンパイル時間 2,436 ms
コンパイル使用メモリ 67,520 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 03:09:31
合計ジャッジ時間 3,277 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 3 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,500 KB
権限があれば一括ダウンロードができます

ソースコード

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