結果

問題 No.1283 Extra Fee
ユーザー dot_haraaidot_haraai
提出日時 2021-06-04 13:25:16
言語 Nim
(2.0.2)
結果
TLE  
実行時間 -
コード長 2,902 bytes
コンパイル時間 5,788 ms
コンパイル使用メモリ 74,520 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-12 01:25:42
合計ジャッジ時間 11,180 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 18) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'times' [UnusedImport]
/home/judge/data/code/Main.nim(2, 26) Warning: imported and not used: 'strformat' [UnusedImport]
/home/judge/data/code/Main.nim(2, 18) Warning: imported and not used: 'future' [UnusedImport]
/home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'critbits' [UnusedImport]
/home/judge/data/code/Main.nim(1, 41) Warning: imported and not used: 'algorithm' [UnusedImport]
/home/judge/data/code/Main.nim(1, 52) Warning: imported and not used: 'tables' [UnusedImport]
/home/judge/data/code/Main.nim(1, 60) Warning: imported and not used: 'sets' [UnusedImport]
/home/judge/data/code/Main.nim(1, 66) Warning: imported and not used: 'lists' [UnusedImport]
/home/judge/data/code/Main.nim(1, 73) Warning: imported and not used: 'intsets' [UnusedImport]

ソースコード

diff #

import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets
import critbits, future, strformat, deques
template `max=`(x,y) = x = max(x,y)
template `min=`(x,y) = x = min(x,y)
template `mod=`(x,y) = x = x mod y
template scan2 = (scan(), scan())
template scan3 = (scan(), scan())
let read* = iterator: string {.closure.} =
    while true: (for s in stdin.readLine.split: yield s)
proc scan(): int = read().parseInt
proc scanf(): float = read().parseFloat
proc toInt(c:char): int =
    return int(c) - int('0')




proc solve():int=
  var
    n = scan()
    m = scan()
    board = newseqwith(n,newseqwith(n,0))
    costS = newseqwith(n,newseqwith(n,int.high.div(4)))
    costG = newseqwith(n,newseqwith(n,int.high.div(4)))
    fromS = newseqwith(n,newseq[(int,int)](n))
    fromG = newseqwith(n,newseq[(int,int)](n))
  costS[0][0]=0
  costG[^1][^1]=0
  for i in 0..<m:
    var
      (h,w,c)=(scan()-1,scan()-1,scan())
    board[h][w]=c
  var
    q = initDeque[(int,int)]()
  q.addLast((0,0))
  while q.len>0:
    var
      (h,w)=q.popFirst()
    if h-1>=0:
      if costS[h-1][w] > costS[h][w]+board[h-1][w]+1:
        costS[h-1][w] = costS[h][w]+board[h-1][w]+1
        q.addLast((h-1,w))
        fromS[h-1][w] = ((h,w))
    if h+1<n:
      if costS[h+1][w] > costS[h][w]+board[h+1][w]+1:
        costS[h+1][w] = costS[h][w]+board[h+1][w]+1
        q.addLast((h+1,w))
        fromS[h+1][w] = ((h,w))
      
    if w-1>=0:
      if costS[h][w-1] > costS[h][w]+board[h][w-1]+1:
        costS[h][w-1] = costS[h][w]+board[h][w-1]+1
        q.addLast((h,w-1))
        fromS[h][w-1] = ((h,w))
      
    if w+1<n:
      if costS[h][w+1] > costS[h][w]+board[h][w+1]+1:
        costS[h][w+1] = costS[h][w]+board[h][w+1]+1
        q.addLast((h,w+1))
        fromS[h][w+1] = ((h,w))
  q.addLast((n-1,n-1))
  while q.len>0:
    var
      (h,w)=q.popFirst()
    if h-1>=0:
      if costG[h-1][w] > costG[h][w]+board[h-1][w]+1:
        costG[h-1][w] = costG[h][w]+board[h-1][w]+1
        q.addLast((h-1,w))
        fromG[h-1][w] = ((h,w))
    if h+1<n:
      if costG[h+1][w] > costG[h][w]+board[h+1][w]+1:
        costG[h+1][w] = costG[h][w]+board[h+1][w]+1
        q.addLast((h+1,w))
        fromG[h+1][w] = ((h,w))
      
    if w-1>=0:
      if costG[h][w-1] > costG[h][w]+board[h][w-1]+1:
        costG[h][w-1] = costG[h][w]+board[h][w-1]+1
        q.addLast((h,w-1))
        fromG[h][w-1] = ((h,w))
      
    if w+1<n:
      if costG[h][w+1] > costG[h][w]+board[h][w+1]+1:
        costG[h][w+1] = costG[h][w]+board[h][w+1]+1
        q.addLast((h,w+1))
        fromG[h][w+1] = ((h,w))
      
    result = costS[n-1][n-1]

    for h in 0..<n:
      for w in 0..<n:
        # (h,w)に通行料金がかかる場合
        if board[h][w]>0:
          var
            (fh,fw) = fromS[h][w]
            (th,tw) = fromG[h][w]
          result.min=2+costS[fh][fw]+costG[th][tw]

    

echo solve()
0