結果

問題 No.2569 はじめてのおつかいHard
ユーザー chaemonchaemon
提出日時 2023-12-02 16:48:12
言語 Nim
(2.0.2)
結果
AC  
実行時間 548 ms / 2,000 ms
コード長 18,172 bytes
コンパイル時間 4,756 ms
コンパイル使用メモリ 96,896 KB
実行使用メモリ 41,088 KB
最終ジャッジ日時 2024-09-26 20:44:40
合計ジャッジ時間 9,179 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
28,160 KB
testcase_01 AC 123 ms
28,288 KB
testcase_02 AC 126 ms
28,416 KB
testcase_03 AC 121 ms
28,416 KB
testcase_04 AC 122 ms
28,288 KB
testcase_05 AC 548 ms
40,576 KB
testcase_06 AC 347 ms
30,848 KB
testcase_07 AC 498 ms
40,704 KB
testcase_08 AC 546 ms
41,088 KB
testcase_09 AC 228 ms
38,912 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import macros
macro Please(x): untyped = nnkStmtList.newTree()

Please use Nim-ACL
Please use Nim-ACL
Please use Nim-ACL


static:
  when not defined SecondCompile:
    # md5sum: 53ca66a715e1dc83a283127c351cfe0b  atcoder.tar.xz

    template getFileName():string = instantiationInfo().filename
    let fn = getFileName()
    block:
      let (output, ex) = gorgeEx("if [ -e ./atcoder ]; then exit 1; else exit 0; fi")
      # doAssert ex == 0, "atcoder directory already exisits"
    discard staticExec("echo \"/Td6WFoAAATm1rRGAgAhARwAAAAQz1jM4Rf/LxxdADCdCIqmAHyeLmzPetXzWpgQcDgKgJF+nO8CaeoEXtPWxPMBhJ5t1kS7wxI8zQ3VL5h388YeZVLzy4TO0LfTJ0JCnHFV1Dr9UWi9e6NX7iJQCxaRdR62LHG4f3XsxTdU4JW7HGL0T1oj4ca+OgbsZy1UFBfm6RFukW6mxynuAbUAYk8RofzSGUkqzA5xr0hxCUNKh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qW6OfiKdTY2vVfPljf7UwZcB3cL8XS7VW8Px2TepydPkiAL5YtOUYVGcEHhUYcfFK45MZoQVtwzYzevUqW7/htKwe8Bnj1fvDZEOnOy8vPe7N3lhTrNlPGuWfFfvmqaUCBGtmxyFQPaYNoxjqef7fEAQ/Rg4+Pc5ZdwKPKxa4czMLcsQSeYW4e7cXwKGU4bSLENCN6ZvEEtgmQ4YxxJ+9vtyjmGaCqp/Rm5ffV5BzW89EByKEiZAt1xI9HBYRXrPtx7bGE01FhUISNYch9APB/9pqg0SyINmanxJpECB4Ot1kuytsLJHxxZXXecUa9nP3E3Rv8pA/1D+W0sedFWfzX7TPAK/Yzh06jhgUamqrxoAiNHAGzYelQ8a6rNIhBr2vh2MPtgii0KFHtMIEG//VTPt8wg6b1klUQQ/X6gKQByYQmwnzYXTk6qbcePqQzd9jkitxKPGAkNAJAPXWWT8v8+C230KC8YRDV89J9182tFqnwvh1a5UoisxYf3JKQZETBXtyhCXP8C1kK1oUspa1qJwOZKShDJMW7buehra4UVx6Mht2nRlrlgiPSApzqUUKFqS5UUTqnpcE6TXbCsGD4lhwftJIn6VWXEQ4KKB/m1Us7FvJbcYlYb9iQmx9D2+2kGPGyl1dGv3OsDrZKh9aIf5TCt5AIZn4i1yq1YWh7OPNprPPNix9J8+FMnV1r1SrYDe5rwRjO/iI3ylrDqU8QHwZ8Z74BemtyVLp9OQWSRh8cJce997nv2wX55w/H6NsjMlfCLFI9h61cvVFjfLd6GqoCDGD6GBzrpsxTalAGNZJq/YwsF7AABql8Vwf7vAuQABuF6AsAQAQLmE/rHEZ/sCAAAAAARZWg==\" | base64 -d > atcoder.tar.xz && tar -Jxvf atcoder.tar.xz")
    let (output, ex) = gorgeEx("nim cpp -d:release -d:SecondCompile -d:danger --path:./ --opt:speed --multimethods:on --warning[SmallLshouldNotBeUsed]:off --checks:off -o:a.out " & fn)
    discard staticExec("rm -rf ./atcoder");doAssert ex == 0, output;quit(0)


when defined SecondCompile:
  const DO_CHECK = false;const DEBUG = false
else:
  const DO_CHECK = true;const DEBUG = true
const
  USE_DEFAULT_TABLE = true
  DO_TEST = false

# see https://github.com/zer0-star/Nim-ACL/tree/master/src/atcoder/extra/header/chaemon_header.nim
include atcoder/extra/header/chaemon_header

# see https://github.com/zer0-star/Nim-ACL/tree/master/src/atcoder/extra/graph/graph_template.nim
import atcoder/extra/graph/graph_template

# see https://github.com/zer0-star/Nim-ACL/tree/master/src/atcoder/extra/graph/dijkstra.nim
import atcoder/extra/graph/dijkstra


proc solve() =
  let N, M = nextInt()
  var g, h = initGraph(N)
  for _ in M:
    let u, v = nextInt() - 1
    let t = nextInt()
    g.addEdge(u, v, t)
    h.addEdge(v, u, t)
  var
    d1 = g.dijkstra(N - 2)
    d2 = g.dijkstra(N - 1)
    e1 = h.dijkstra(N - 2)
    e2 = h.dijkstra(N - 1)
  for k in N - 2:
    var ans = int.inf
    # k -> N - 2 -> N - 1 -> k
    ans.min= min(int.inf, e1[k] + d1[N - 1]) + d2[k]
    # k -> N - 1 -> N - 2 -> k
    ans.min= min(int.inf, e2[k] + d2[N - 2]) + d1[k]
    if ans == int.inf:
      echo -1
    else:
      echo ans
  discard

solve()

0