結果

問題 No.2565 はじめてのおつかい
ユーザー chaemonchaemon
提出日時 2023-12-02 15:57:19
言語 Nim
(2.0.2)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 18,006 bytes
コンパイル時間 4,559 ms
コンパイル使用メモリ 96,896 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-09-26 19:34:24
合計ジャッジ時間 8,302 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 84 ms
16,256 KB
testcase_04 AC 71 ms
16,256 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 58 ms
9,088 KB
testcase_07 AC 28 ms
6,528 KB
testcase_08 AC 30 ms
6,528 KB
testcase_09 AC 51 ms
8,960 KB
testcase_10 AC 38 ms
7,040 KB
testcase_11 AC 85 ms
13,056 KB
testcase_12 AC 18 ms
5,504 KB
testcase_13 AC 36 ms
7,168 KB
testcase_14 AC 62 ms
10,368 KB
testcase_15 AC 65 ms
9,856 KB
testcase_16 AC 56 ms
14,464 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 16 ms
7,168 KB
testcase_19 AC 76 ms
12,032 KB
testcase_20 AC 68 ms
11,008 KB
testcase_21 AC 57 ms
10,880 KB
testcase_22 AC 31 ms
8,064 KB
testcase_23 AC 40 ms
8,320 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 68 ms
11,136 KB
testcase_26 AC 41 ms
7,936 KB
testcase_27 AC 58 ms
11,520 KB
testcase_28 AC 75 ms
11,904 KB
testcase_29 AC 87 ms
13,568 KB
testcase_30 AC 63 ms
12,288 KB
testcase_31 AC 67 ms
11,648 KB
testcase_32 AC 38 ms
7,936 KB
testcase_33 AC 64 ms
11,776 KB
testcase_34 AC 73 ms
10,752 KB
testcase_35 AC 59 ms
13,184 KB
testcase_36 AC 70 ms
11,648 KB
testcase_37 AC 39 ms
8,192 KB
testcase_38 AC 69 ms
10,752 KB
testcase_39 AC 61 ms
9,728 KB
testcase_40 AC 77 ms
13,440 KB
testcase_41 AC 76 ms
14,080 KB
testcase_42 AC 41 ms
8,064 KB
testcase_43 AC 59 ms
10,112 KB
testcase_44 AC 31 ms
6,656 KB
testcase_45 AC 15 ms
5,376 KB
testcase_46 AC 71 ms
10,240 KB
testcase_47 AC 40 ms
8,064 KB
testcase_48 AC 40 ms
7,040 KB
testcase_49 AC 18 ms
5,376 KB
testcase_50 AC 47 ms
9,344 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 38 ms
9,216 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: ba55ef66a168f7cd9eef800705fb7c52  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/LyBdADCdCIqmAHyeLmzPetXzWpgQcDgKgJF+nO8CaeoEXtWXd7QcS0wL1Mupqq3HLnU5tB3XJsnjoexaAotINo9hsuZ72jwe+XrGnf6BthoBRM/VesyuMEn9VghWTbqkpp5U06qmZ6JYDQXXSTSmPCmJBrL2HzUjBIrXfZ4aIPUZfe+Fh9SZ+fzynwvR2K2Rrhs7z75l1UCayq40zP41ASJ8Irh5SxwujPMClbo7ndPwPAME89g8H15wVYiyp+zRJm4FiZDgy5QuRYPIGaZ0R6eySbKtRD4Aw09LqOIwTfg6dDkJ+VDmRqPQ+zyOmVxmxy8DZnFC1gZrQ3dZxwWEr+/qKmYf5UfyoIKfPhQm0iz6bhSaFeyJ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bcsHnk75dfT8BKs8i6Eilv0P1nQcfEAxs3x50x1U5PQRBTm8NiOUZshhHBTeNqnIbETQhe6jpK/52qchdVei6vQmeqX5W/goSOXaGiiJ4CNHE7cGyXnPDeKYmEX2iocb/CdL6sVoxyHLmQEmdxfkpU6st8fscCRPSYQKgTuU/orzizpteiibBUtJddHcQpBjMhFiSiFg2PTBIubDRfcu7YJnpo+5UYtFyBMExqDXmeN5sWDKUC/OWpS6rtgEmKRtylfhMc7kd+MxV6xPJ+Us8rqZ3UobZVBilnRefpFykqWT4NqaYbUVRMg/gTFOFFdzIVV17iu8JM5SUAB70oa3EFbWADPePzICb7Fr5HEV3wCC8iodn5dl8eetdxqgLOQj2Y5kcwpFzGOfoKKVM1HSQHUYu59VUtOnWYK4hF5ANblA70VjuLYwzwNogq0dLwFteqCk0BT8nRsiiScwFTHAKgrSNLWN8nf1H4FcFd2DfywBPvZOqWhJ0/2KUcMl/gNAr3xEVV5EpJcxefW4ZyvNMe1xSp4jzGMzmx0q1HICP0l6FSS5AEgaihZ2ed0iqnpEtUN4++/BNdk08EqQWiPItHWgsNWM6wAAwNuPQHq1qH8AAbxegLAEAFb7FWWxxGf7AgAAAAAEWVo=\" | 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 = initGraph(N)
  for _ in M:
    let u, v = nextInt() - 1
    g.addEdge(u, v)
  var
    d0 = g.dijkstra(0)
    d1 = g.dijkstra(N - 2)
    d2 = g.dijkstra(N - 1)
    ans = int.inf
  ans.min= min(int.inf, d0[N - 2] + d1[N - 1]) + d2[0]
  ans.min= min(int.inf, d0[N - 1] + d2[N - 2]) + d1[0]
  if ans == int.inf:
    echo -1
  else:
    echo ans
  discard

solve()

0