結果
| 問題 |
No.1111 コード進行
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-10 21:51:46 |
| 言語 | Nim (2.2.0) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 48 |
コンパイルメッセージ
/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]
ソースコード
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