結果
問題 | No.1112 冥界の音楽 |
ユーザー | semisagi |
提出日時 | 2020-07-10 22:43:01 |
言語 | Swift (5.10.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 2,891 bytes |
コンパイル時間 | 1,436 ms |
コンパイル使用メモリ | 130,496 KB |
実行使用メモリ | 9,592 KB |
最終ジャッジ日時 | 2024-05-07 22:23:44 |
合計ジャッジ時間 | 3,104 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
9,216 KB |
testcase_01 | AC | 9 ms
9,216 KB |
testcase_02 | AC | 10 ms
9,344 KB |
testcase_03 | AC | 9 ms
9,088 KB |
testcase_04 | AC | 10 ms
9,472 KB |
testcase_05 | AC | 9 ms
9,216 KB |
testcase_06 | AC | 10 ms
9,344 KB |
testcase_07 | AC | 8 ms
9,216 KB |
testcase_08 | AC | 9 ms
9,088 KB |
testcase_09 | AC | 9 ms
9,216 KB |
testcase_10 | AC | 9 ms
9,216 KB |
testcase_11 | AC | 10 ms
9,216 KB |
testcase_12 | AC | 10 ms
9,216 KB |
testcase_13 | AC | 9 ms
9,216 KB |
testcase_14 | AC | 20 ms
9,216 KB |
testcase_15 | AC | 14 ms
9,344 KB |
testcase_16 | AC | 13 ms
9,344 KB |
testcase_17 | AC | 16 ms
9,344 KB |
testcase_18 | AC | 16 ms
9,344 KB |
testcase_19 | AC | 13 ms
9,344 KB |
testcase_20 | AC | 14 ms
9,344 KB |
testcase_21 | AC | 19 ms
9,344 KB |
testcase_22 | AC | 19 ms
9,344 KB |
testcase_23 | AC | 14 ms
9,472 KB |
testcase_24 | AC | 29 ms
9,592 KB |
testcase_25 | AC | 28 ms
9,592 KB |
testcase_26 | AC | 26 ms
9,424 KB |
testcase_27 | AC | 25 ms
9,456 KB |
testcase_28 | AC | 28 ms
9,452 KB |
testcase_29 | AC | 27 ms
9,324 KB |
testcase_30 | AC | 35 ms
9,408 KB |
testcase_31 | AC | 26 ms
9,416 KB |
testcase_32 | AC | 36 ms
9,456 KB |
testcase_33 | AC | 27 ms
9,460 KB |
testcase_34 | AC | 26 ms
9,448 KB |
testcase_35 | AC | 27 ms
9,464 KB |
testcase_36 | AC | 60 ms
9,588 KB |
ソースコード
struct Scanner { private var stack = [String]() private var index = 0 mutating func peek() -> String { if stack.count == index { stack += readLine()!.split(separator: " ").map{ String($0) } } return stack[index] } mutating func next() -> String { let value = peek() index += 1 return value } mutating func nextInt() -> Int { return Int(next())! } mutating func nextDouble() -> Double { return Double(next())! } } let MOD = 1000000007 struct Zn { let n: Int init(_ n: Int) { self.n = n } static func + (lhs: Self, rhs: Self) -> Self { let n = lhs.n + rhs.n return Zn(n < MOD ? n : n - MOD) } static func - (lhs: Self, rhs: Self) -> Self { Zn((lhs.n - rhs.n + MOD) % MOD) } static func * (lhs: Self, rhs: Self) -> Self { Zn((lhs.n * rhs.n) % MOD) } static func += (lhs: inout Self, rhs: Self) { lhs = lhs + rhs } } let U = 6 * 6 struct Matrix { var A = [Zn](repeating: Zn(0), count: U * U) subscript(k: (Int, Int)) -> Zn { get { return A[k.0 * U + k.1] } set { A[k.0 * U + k.1] = newValue } } static var E: Self { var value = Matrix() for i in 0 ..< U { value[(i, i)] = Zn(1) } return value } static func * (lhs: Self, rhs: Self) -> Self { var value = Matrix() for i in 0 ..< U { for k in 0 ..< U { for j in 0 ..< U { value[(i, j)] += lhs[(i, k)] * rhs[(k, j)] } } } return value } func pow(_ k: Int) -> Self { if k == 0 { return .E } else if k % 2 == 1 { return self.pow(k - 1) * self } else { return (self * self).pow(k / 2) } } } var scanner = Scanner() let K = scanner.nextInt() let M = scanner.nextInt() let N = scanner.nextInt() var matrix = Matrix() func index(_ i: Int, _ j: Int) -> Int { i * 6 + j } var table = [Bool](repeating: false, count: 6 * 6 * 6) func tableIndex(_ i: Int, _ j: Int, _ k: Int) -> Int { (i * 6 + j) * 6 + k } for _ in 0 ..< M { let P = scanner.nextInt() - 1 let Q = scanner.nextInt() - 1 let R = scanner.nextInt() - 1 table[tableIndex(P, Q, R)] = true } for i in 0 ..< K { for j in 0 ..< K { for k in 0 ..< K { if table[tableIndex(i, j, k)] { matrix[(index(j, k), index(i, j))] += Zn(1) } } } } matrix = matrix.pow(N - 2) var answer = Zn(0) for i in 0 ..< U where i % 6 == 0 { for j in 0 ..< U where j / 6 == 0 { answer += matrix[(i, j)] } } print(answer.n)