結果
問題 | No.1112 冥界の音楽 |
ユーザー | xuanji |
提出日時 | 2020-07-10 23:14:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 255 ms / 2,000 ms |
コード長 | 1,257 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 76,980 KB |
最終ジャッジ日時 | 2024-10-11 18:23:33 |
合計ジャッジ時間 | 4,108 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
70,016 KB |
testcase_01 | AC | 40 ms
52,352 KB |
testcase_02 | AC | 40 ms
52,472 KB |
testcase_03 | AC | 39 ms
52,352 KB |
testcase_04 | AC | 41 ms
52,736 KB |
testcase_05 | AC | 39 ms
52,608 KB |
testcase_06 | AC | 85 ms
76,292 KB |
testcase_07 | AC | 38 ms
52,480 KB |
testcase_08 | AC | 43 ms
59,392 KB |
testcase_09 | AC | 58 ms
67,456 KB |
testcase_10 | AC | 38 ms
52,608 KB |
testcase_11 | AC | 60 ms
71,680 KB |
testcase_12 | AC | 38 ms
52,608 KB |
testcase_13 | AC | 62 ms
72,576 KB |
testcase_14 | AC | 103 ms
76,288 KB |
testcase_15 | AC | 73 ms
75,796 KB |
testcase_16 | AC | 38 ms
52,352 KB |
testcase_17 | AC | 81 ms
76,032 KB |
testcase_18 | AC | 85 ms
76,192 KB |
testcase_19 | AC | 41 ms
52,352 KB |
testcase_20 | AC | 72 ms
75,700 KB |
testcase_21 | AC | 109 ms
76,288 KB |
testcase_22 | AC | 110 ms
76,000 KB |
testcase_23 | AC | 78 ms
75,752 KB |
testcase_24 | AC | 43 ms
52,864 KB |
testcase_25 | AC | 41 ms
52,480 KB |
testcase_26 | AC | 63 ms
67,456 KB |
testcase_27 | AC | 69 ms
67,328 KB |
testcase_28 | AC | 74 ms
76,416 KB |
testcase_29 | AC | 42 ms
53,120 KB |
testcase_30 | AC | 136 ms
76,380 KB |
testcase_31 | AC | 73 ms
76,032 KB |
testcase_32 | AC | 133 ms
76,696 KB |
testcase_33 | AC | 58 ms
67,328 KB |
testcase_34 | AC | 38 ms
52,608 KB |
testcase_35 | AC | 59 ms
67,456 KB |
testcase_36 | AC | 255 ms
76,980 KB |
ソースコード
#!/usr/bin/env python3 MODULUS = 10**9+7 class Mat(list): def __matmul__(self, B) : A = self return Mat([[sum(A[i][k]*B[k][j] for k in range(len(B))) % MODULUS for j in range(len(B[0])) ] for i in range(len(A))]) def identity(size): size = range(size) return [[(i==j)*1 for i in size] for j in size] def power(F, n): result = Mat(identity(len(F))) b = Mat(F) while n > 0: if (n%2) == 0: b = b @ b n //= 2 else: result = b @ result b = b @ b n //= 2 return result K, M, N = input().split(' ') K = int(K) M = int(M) N = int(N) adjacency = [] for _ in range(K*K): row = [0]*(K*K) adjacency += [row] for _ in range(M): P, Q, R = input().split(' ') P = int(P) Q = int(Q) R = int(R) P -= 1 Q -= 1 R -= 1 adjacency[P*K + Q][Q*K+R] = 1 if N == 1: print(1) elif N == 2: print(adjacency[0][0]) else: adjacency = power(adjacency, N-2) ret = 0 for p in [0]: for q in range(K): for r in range(K): for s in [0]: ret += adjacency[p*K+q][r*K+s] ret = ret % MODULUS print(ret)