結果

問題 No.1111 コード進行
ユーザー HaarHaar
提出日時 2020-07-10 21:51:46
言語 Nim
(2.0.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 3,512 bytes
コンパイル時間 4,917 ms
コンパイル使用メモリ 66,888 KB
実行使用メモリ 235,008 KB
最終ジャッジ日時 2023-08-01 17:37:59
合計ジャッジ時間 7,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 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 4 ms
4,980 KB
testcase_07 AC 4 ms
4,908 KB
testcase_08 AC 3 ms
4,832 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,580 KB
testcase_11 AC 3 ms
4,500 KB
testcase_12 AC 5 ms
4,644 KB
testcase_13 AC 3 ms
4,520 KB
testcase_14 AC 6 ms
4,908 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 6 ms
5,556 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 4 ms
5,372 KB
testcase_23 AC 3 ms
4,884 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 9 ms
6,932 KB
testcase_26 AC 6 ms
5,120 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 7 ms
6,900 KB
testcase_29 AC 19 ms
16,872 KB
testcase_30 AC 27 ms
12,752 KB
testcase_31 AC 3 ms
4,388 KB
testcase_32 AC 50 ms
18,104 KB
testcase_33 AC 52 ms
12,120 KB
testcase_34 AC 6 ms
6,296 KB
testcase_35 AC 11 ms
9,372 KB
testcase_36 AC 194 ms
111,696 KB
testcase_37 AC 114 ms
90,516 KB
testcase_38 AC 64 ms
45,340 KB
testcase_39 AC 90 ms
26,332 KB
testcase_40 AC 147 ms
86,900 KB
testcase_41 AC 34 ms
26,208 KB
testcase_42 AC 133 ms
97,624 KB
testcase_43 AC 95 ms
55,524 KB
testcase_44 AC 36 ms
31,192 KB
testcase_45 AC 65 ms
49,972 KB
testcase_46 AC 20 ms
19,676 KB
testcase_47 AC 264 ms
20,324 KB
testcase_48 AC 248 ms
235,008 KB
testcase_49 AC 166 ms
166,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 42) Warning: imported and not used: 'bitops' [UnusedImport]
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'strutils' [UnusedImport]
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'sugar' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,sugar,algorithm,bitops,math

proc scanf*(formatstr: cstring){.header: "<stdio.h>", importc: "scanf", varargs.}
proc nextInt*(): int32 = scanf("%d", addr result)
proc nextLong*(): int64 = scanf("%lld", addr result)
proc nextFloat*(): float64 = scanf("%lf", addr result)
proc getchar*(): char {.header: "<stdio.h>", importc: "getchar".}
proc nextChar*(): char =
  while true:
    let c = getchar()
    if c.ord >= 0x21 and c.ord <= 0x7e:
      result = c
      break

proc nextstr*(): string =
  var ok = false
  while true:
    let c = getchar()
    if c.ord >= 0x21 and c.ord <= 0x7e: ok = true
    elif ok: break

    if ok:
      result.add(c)
      


template `max=`*(x, y) = x = max(x, y)
template `min=`*(x, y) = x = min(x, y)
template times*(n: int; body: untyped): untyped = (for _ in 0 ..< n: body)
proc `<-`*[T, U](a: var T, b: U): T =
  a = b
  return a

template `<<`(a: untyped, b: int): untyped = (a shl b)
template `>>`(a: untyped, b: int): untyped = (a shr b)

type
  ModInt*[M: static[int]] = distinct int64

proc `+`*[M](lhs, rhs: ModInt[M]): ModInt[M] {.noSideEffect.} =
  var t = int64(lhs) + int64(rhs)
  if t >= M: t -= M
  return ModInt[M](t)

proc `+`*[M](lhs: ModInt[M], rhs: int64): ModInt[M] {.noSideEffect.} =
  return ModInt[M]((int64(lhs) + rhs mod M) mod M)

proc `-`*[M](lhs, rhs: ModInt[M]): ModInt[M] {.noSideEffect.} =
  var t = int64(lhs) - int64(rhs)
  if t < 0: t += M
  return ModInt[M](t)

proc `-`*[M](lhs: ModInt[M], rhs: int64): ModInt[M] {.noSideEffect.} =
  var t = int64(lhs) - rhs mod M
  if t < 0: t += M
  return ModInt[M](t)

proc `*`*[M](lhs, rhs: ModInt[M]): ModInt[M] {.noSideEffect.} = return ModInt[M]((int64(lhs) * int64(rhs)) mod M)
proc `*`*[M](lhs: ModInt[M], rhs: int64): ModInt[M] {.noSideEffect.} = return ModInt[M]((int64(lhs) * rhs mod M) mod M)

proc pow*[M](a: ModInt[M], p: int64): ModInt[M] {.noSideEffect.} =
  var
    ret = ModInt[M](1)
    a = a
    p = p

  while p > 0:
    if (p and 1) == 1: ret = ret * a
    a = a * a
    p = p shr 1

  return ret

proc inv*[M](a: ModInt[M]): ModInt[M] {.noSideEffect.} =
  var
    a: int64 = int64(a)
    b: int64 = M
    u: int64 = 1
    v: int64 = 0

  while b != 0:
    let t = a div b
    a -= t * b
    swap(a, b)
    u -= t * v
    swap(u, v)

  u = u mod M
  if u < 0: u += M

  return ModInt[M](u)

proc `/`*[M](lhs, rhs: ModInt[M]): ModInt[M] {.noSideEffect.} = return lhs * rhs.inv

proc frac*[M](x: typedesc[ModInt[M]], a: int64, b: int64): ModInt[M] {.noSideEffect.} = return ModInt[M](a) * ModInt[M](b).inv

proc `$`*[M](a: ModInt[M]): string {.noSideEffect.} = $(int64(a))
proc `+=`*[M](lhs: var ModInt[M], rhs: ModInt[M]) = lhs = lhs + rhs
proc `-=`*[M](lhs: var ModInt[M], rhs: ModInt[M]) = lhs = lhs - rhs
proc `*=`*[M](lhs: var ModInt[M], rhs: ModInt[M]) = lhs = lhs * rhs
proc `/=`*[M](lhs: var ModInt[M], rhs: ModInt[M]) = lhs = lhs / rhs

proc zero*[M](t: type[ModInt[M]]): ModInt[M] {.noSideEffect.} = return ModInt[M](0)
proc one*[M](t: type[ModInt[M]]): ModInt[M] {.noSideEffect.} = return ModInt[M](1)



type mint = ModInt[1_000_000_007]




let N = nextint()
let M = nextint()
let K = nextint()

var data = newSeqWith(M, (nextint() - 1, nextint() - 1, nextint()))

var dp: array[330, array[300, array[330, mint]]]


for i in 0 ..< 300: dp[1][i][0] = 1.mint



for i in 1 ..< N:
  for (p, q, c) in data:
    for j in 0 .. K:
      if j + c <= K: dp[i + 1][q][j + c] += dp[i][p][j]

var ans = 0.mint
for i in 0 ..< 300: ans += dp[N][i][K]

echo ans


0