結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
chaemon
|
| 提出日時 | 2020-01-17 21:38:01 |
| 言語 | Nim (2.2.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,540 bytes |
| コンパイル時間 | 4,010 ms |
| コンパイル使用メモリ | 72,752 KB |
| 実行使用メモリ | 77,600 KB |
| 最終ジャッジ日時 | 2024-06-25 19:00:49 |
| 合計ジャッジ時間 | 13,929 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 WA * 5 |
コンパイルメッセージ
/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]
ソースコード
#{{{ 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()
chaemon