結果
問題 | No.1112 冥界の音楽 |
ユーザー | Haar |
提出日時 | 2020-07-10 22:13:56 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 4,596 bytes |
コンパイル時間 | 3,519 ms |
コンパイル使用メモリ | 67,204 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 09:31:07 |
合計ジャッジ時間 | 4,727 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 1 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 3 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 3 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 10 ms
5,248 KB |
testcase_15 | AC | 4 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 4 ms
5,248 KB |
testcase_18 | AC | 4 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 9 ms
5,248 KB |
testcase_22 | AC | 9 ms
5,248 KB |
testcase_23 | AC | 3 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 10 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 12 ms
5,248 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 30 ms
5,248 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]
ソースコード
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 SquareMatrix*[T] = object N: int data: seq[seq[T]] proc make*[T](t: typedesc[SquareMatrix[T]], N: int): SquareMatrix[T] {.noSideEffect.} = return SquareMatrix[T](N: N, data: newSeqWith(N, newSeqWith(N, 0.T))) proc one*[T](t: typedesc[SquareMatrix[T]], N: int): SquareMatrix[T] {.noSideEffect.} = var ret = SquareMatrix[T].make(N) for i in 0 ..< N: ret.data[i][i] = 1.T return ret proc init_with_seq*[T](self: var SquareMatrix[T], value: seq[seq[T]]) = let N = self.N for i in 0 ..< N: for j in 0 ..< N: self.data[i][j] = value[i][j] proc `*`*[T](lhs, rhs: SquareMatrix[T]): SquareMatrix[T] {.noSideEffect.} = let N = lhs.N var ret = SquareMatrix[T].make(N) for i in 0 ..< N: for j in 0 ..< N: for k in 0 ..< N: ret.data[i][j] += lhs.data[i][k] * rhs.data[k][j] return ret proc `^`*[T](self: SquareMatrix[T], p: int64): SquareMatrix[T] {.noSideEffect.} = let N = self.N var ret = SquareMatrix[T].one(N) a = self p = p while p > 0: if (p and 1) == 1: ret = ret * a a = a * a p = p div 2 return ret type mint = ModInt[1_000_000_007] let K = nextint() let M = nextint() let N = nextlong() let data = newSeqWith(M, (nextint() - 1, nextint() - 1, nextint() - 1)) var mat = SquareMatrix[mint].make(K * K) for (x, y, z) in data: mat.data[y * K + z][x * K + y] += 1.mint mat = mat ^ (N - 2) #for a in mat.data: echo a var ans = 0.mint for i in 0 ..< K: for j in 0 ..< K: ans += mat.data[i * K][j] echo ans