結果

問題 No.971 いたずらっ子
ユーザー chaemonchaemon
提出日時 2020-01-17 21:38:01
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,540 bytes
コンパイル時間 3,769 ms
コンパイル使用メモリ 67,692 KB
実行使用メモリ 77,076 KB
最終ジャッジ日時 2023-09-08 01:55:04
合計ジャッジ時間 15,964 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1,219 ms
76,796 KB
testcase_04 AC 1,146 ms
71,972 KB
testcase_05 AC 1,225 ms
76,368 KB
testcase_06 AC 924 ms
63,648 KB
testcase_07 WA -
testcase_08 AC 303 ms
30,088 KB
testcase_09 AC 287 ms
21,428 KB
testcase_10 AC 8 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,380 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 57) Warning: imported and not used: 'strutils' [UnusedImport]
/home/judge/data/code/Main.nim(2, 45) Warning: imported and not used: 'math' [UnusedImport]
/home/judge/data/code/Main.nim(2, 29) Warning: imported and not used: 'tables' [UnusedImport]
/home/judge/data/code/Main.nim(2, 37) Warning: imported and not used: 'macros' [UnusedImport]

ソースコード

diff #

#{{{ header
import algorithm, sequtils, tables, macros, math, sets, strutils
when defined(MYDEBUG):
  import header

proc scanf(formatstr: cstring){.header: "<stdio.h>", varargs.}
proc getchar(): char {.header: "<stdio.h>", varargs.}
proc nextInt(): int = scanf("%lld",addr result)
proc nextFloat(): float = scanf("%lf",addr result)
proc nextString(): string =
  var get = false
  result = ""
  while true:
    var c = getchar()
    if int(c) > int(' '):
      get = true
      result.add(c)
    else:
      if get: break
      get = false
template `max=`*(x,y:typed):void = x = max(x,y)
template `min=`*(x,y:typed):void = x = min(x,y)
template inf(T): untyped = ((T(1) shl T(sizeof(T)*8-2)) - 1)
#}}}

import heapqueue

proc main():void =
  let H, W = nextInt()
  let a = newSeqWith(H, nextString())
  var g = newSeqWith(H, newSeqWith(W, 0))
  for i in 0..<H:
    for j in 0..<W:
      if a[i][j] == 'k':
        g[i][j] = i + j
      else:
        g[i][j] = 0
  var dist = newSeqWith(H, newSeqWith(W, int.inf))
  proc inner(x, y:int):bool = (0 <= x and x < H and 0 <= y and y < W)
  let
    vx = [0,1, 0,-1]
    vy = [1,0,-1, 0]
  var q = initHeapQueue[(int,(int,int))]()
  dist[0][0] = 0
  q.push((0,(0,0)))
  while q.len > 0:
    let t = q.pop()
    let (x, y) = t[1]
    for i in 0..<4:
      let (x2, y2) = (x + vx[i], y + vy[i])
      if not inner(x2, y2): continue
      let d2 = dist[x][y] + g[x2][y2] + 1
      if d2 < dist[x2][y2]:
        dist[x2][y2] = d2
        q.push((d2, (x2, y2)))
  echo dist[H-1][W-1]
  discard

main()
0