結果

問題 No.20 砂漠のオアシス
ユーザー むらためむらため
提出日時 2019-01-28 07:46:16
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,633 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 56,888 KB
最終ジャッジ日時 2023-09-14 03:08:50
合計ジャッジ時間 981 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(32, 15) Error: undeclared identifier: 'newHeapQueue'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (3, 2): 'heapqueue' [module declared in /home/judge/data/code/Main.nim(3, 8)]
 (3, 4): 'initHeapQueue' [proc declared in /nim-1.6.12/lib/pure/collections/heapqueue.nim(54, 6)]
 (3, 4): 'toHeapQueue' [proc declared in /nim-1.6.12/lib/pure/collections/heapqueue.nim(139, 6)]

ソースコード

diff #

{.checks: off, optimization: speed.}
import sequtils,strutils,algorithm
import heapqueue
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y)= (x = max(x,y))
template `min=`*(x,y)= (x = min(x,y))

const dxdy4 :seq[tuple[x,y:int]] = @[(0,1),(1,0),(0,-1),(-1,0)]

# 0以下で死亡 / V - Lxy => Oasis(v *= 2,once)
# N <= 200, V <= 500, Lxy <= 9
# x:N * y:N * use:2 => V
# 最短でゴール or 最短でオアシス +最短でゴールのみ
let n = scan()
let v = scan()
let ox = scan() - 1
let oy = scan() - 1
var L = newSeqWith(n,newSeqUninitialized[int](n))
for y in 0..<n:
  for x in 0..<n:
    L[x][y] = scan()
type field = tuple[x,y,v:int]
proc `<`(x,y:field):bool = (x.v > y.v)
proc twoFactorDijkestra(sx,sy,sv:int,checkOasis:bool = true):void =
  var closed = newSeqWith(n,newSeq[bool](n))
  var opens = newHeapQueue[field]()
  opens.push((sx,sy,sv))
  while opens.len() > 0:
    let (x,y,v) = opens.pop()
    if closed[x][y] : continue
    closed[x][y] = true
    if checkOasis and x == ox and y == oy:
      twoFactorDijkestra(x,y,v * 2,false)
      continue
    for d in dxdy4:
      let (nx,ny) = (d.x + x,d.y + y)
      if nx < 0 or ny < 0 or nx >= n or ny >= n : continue
      var n_v = v - L[nx][ny]
      if n_v <= 0 : continue
      if not closed[nx][ny]:
        opens.push((nx,ny,n_v))
        if nx == n-1 and ny == n-1:
          quit "YES",0
twoFactorDijkestra(0,0,v)
echo "NO"
0