結果

問題 No.1111 コード進行
ユーザー HaarHaar
提出日時 2020-07-10 21:51:46
言語 Nim
(2.0.2)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 3,512 bytes
コンパイル時間 3,555 ms
コンパイル使用メモリ 66,176 KB
実行使用メモリ 234,880 KB
最終ジャッジ日時 2024-10-11 08:55:41
合計ジャッジ時間 6,482 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 3 ms
5,248 KB
testcase_05 AC 3 ms
5,248 KB
testcase_06 AC 4 ms
5,248 KB
testcase_07 AC 4 ms
5,248 KB
testcase_08 AC 4 ms
5,248 KB
testcase_09 AC 4 ms
5,248 KB
testcase_10 AC 4 ms
5,248 KB
testcase_11 AC 3 ms
5,248 KB
testcase_12 AC 5 ms
5,248 KB
testcase_13 AC 3 ms
5,248 KB
testcase_14 AC 7 ms
5,248 KB
testcase_15 AC 3 ms
5,248 KB
testcase_16 AC 6 ms
5,632 KB
testcase_17 AC 3 ms
5,248 KB
testcase_18 AC 2 ms
5,248 KB
testcase_19 AC 2 ms
5,248 KB
testcase_20 AC 2 ms
5,248 KB
testcase_21 AC 2 ms
5,248 KB
testcase_22 AC 4 ms
5,504 KB
testcase_23 AC 4 ms
5,248 KB
testcase_24 AC 3 ms
5,248 KB
testcase_25 AC 9 ms
6,784 KB
testcase_26 AC 6 ms
5,248 KB
testcase_27 AC 3 ms
5,248 KB
testcase_28 AC 7 ms
6,656 KB
testcase_29 AC 19 ms
16,896 KB
testcase_30 AC 29 ms
12,800 KB
testcase_31 AC 3 ms
5,248 KB
testcase_32 AC 52 ms
17,920 KB
testcase_33 AC 56 ms
11,904 KB
testcase_34 AC 7 ms
6,144 KB
testcase_35 AC 11 ms
9,088 KB
testcase_36 AC 205 ms
111,616 KB
testcase_37 AC 115 ms
90,624 KB
testcase_38 AC 66 ms
45,184 KB
testcase_39 AC 94 ms
26,240 KB
testcase_40 AC 160 ms
86,656 KB
testcase_41 AC 35 ms
25,856 KB
testcase_42 AC 138 ms
97,280 KB
testcase_43 AC 100 ms
55,296 KB
testcase_44 AC 38 ms
31,360 KB
testcase_45 AC 70 ms
49,920 KB
testcase_46 AC 20 ms
19,456 KB
testcase_47 AC 277 ms
20,224 KB
testcase_48 AC 239 ms
234,880 KB
testcase_49 AC 169 ms
166,656 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