結果

問題 No.801 エレベーター
ユーザー ikdikd
提出日時 2019-03-18 10:54:56
言語 Nim
(2.0.2)
結果
AC  
実行時間 472 ms / 2,000 ms
コード長 811 bytes
コンパイル時間 3,105 ms
コンパイル使用メモリ 68,960 KB
実行使用メモリ 87,692 KB
最終ジャッジ日時 2023-09-14 15:28:51
合計ジャッジ時間 11,319 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
5,008 KB
testcase_04 AC 7 ms
4,872 KB
testcase_05 AC 7 ms
5,248 KB
testcase_06 AC 7 ms
5,216 KB
testcase_07 AC 7 ms
5,076 KB
testcase_08 AC 7 ms
4,920 KB
testcase_09 AC 8 ms
5,112 KB
testcase_10 AC 8 ms
4,956 KB
testcase_11 AC 7 ms
5,068 KB
testcase_12 AC 7 ms
5,100 KB
testcase_13 AC 466 ms
87,532 KB
testcase_14 AC 465 ms
87,588 KB
testcase_15 AC 468 ms
87,300 KB
testcase_16 AC 466 ms
87,292 KB
testcase_17 AC 466 ms
87,588 KB
testcase_18 AC 467 ms
87,592 KB
testcase_19 AC 464 ms
87,412 KB
testcase_20 AC 465 ms
87,628 KB
testcase_21 AC 465 ms
87,496 KB
testcase_22 AC 472 ms
87,504 KB
testcase_23 AC 388 ms
87,508 KB
testcase_24 AC 386 ms
87,416 KB
testcase_25 AC 389 ms
87,528 KB
testcase_26 AC 387 ms
87,612 KB
testcase_27 AC 385 ms
87,348 KB
testcase_28 AC 282 ms
87,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

const mo: int64 = 1000000000 + 7
proc add(a: var int64, b: int64) =
  a += b
  while a >= mo:
    a -= mo
proc sub(a: var int64, b: int64) =
  a -= b
  while a < 0:
    a += mo

proc main() =
  let
    nmk = stdin.readLine.strip.split.map(parseInt)
    (n, m, k) = (nmk[0], nmk[1], nmk[2])
    lr = (0..<m).mapIt(stdin.readLine.strip.split.map(parseInt))

  var dp = newSeqWith(k + 1, newSeq[int64](n + 1))
  dp[0][0] = 1
  for i in 0..<k:
    var acc = newSeq[int64](n + 1)
    for j in 0..<n:
      add(acc[j + 1], acc[j] + dp[i][j])
    for s in lr:
      var ad = acc[s[1]] - acc[s[0] - 1]
      if ad < 0:
        ad += mo
      add(dp[i + 1][s[0] - 1], ad)
      sub(dp[i + 1][s[1]], ad)
    for j in 0..<n:
      add(dp[i + 1][j + 1], dp[i + 1][j])

  echo dp[k][n - 1]
main()
0