結果

問題 No.1112 冥界の音楽
ユーザー brthyyjpbrthyyjp
提出日時 2020-10-13 05:34:51
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 1,394 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 18,020 KB
最終ジャッジ日時 2023-09-27 23:57:36
合計ジャッジ時間 7,098 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
18,020 KB
testcase_01 AC 15 ms
8,452 KB
testcase_02 AC 14 ms
8,112 KB
testcase_03 AC 14 ms
8,368 KB
testcase_04 AC 15 ms
8,092 KB
testcase_05 AC 15 ms
8,052 KB
testcase_06 AC 763 ms
8,800 KB
testcase_07 AC 15 ms
8,448 KB
testcase_08 AC 15 ms
8,368 KB
testcase_09 AC 41 ms
8,108 KB
testcase_10 AC 16 ms
8,112 KB
testcase_11 AC 118 ms
8,052 KB
testcase_12 AC 15 ms
8,056 KB
testcase_13 AC 16 ms
8,512 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

k, m, n = map(int, input().split())
mod =10**9+7
PQR = []
for i in range(m):
    p, q, r = map(int, input().split())
    p, q, r = p-1, q-1, r-1
    PQR.append((p, q, r))

if n == 3:
    ans = 0
    for i in range(m):
        p1, q1, r1 = PQR[i]
        if p1 == 0 and r1 == 0:
            ans += 1
    print(ans)
    exit()


A = [[0]*m for _ in range(m)]

for i in range(m):
    p1, q1, r1 = PQR[i]
    for j in range(m):
        p2, q2, r2 = PQR[j]
        if q1 == p2 and r1 == q2:
            A[i][j] = 1

C = [[0]*m for _ in range(m)]
for i in range(m):
    p1, q1, r1 = PQR[i]
    if p1 != 0:
        continue
    for j in range(m):
        p2, q2, r2 = PQR[j]
        if q1 == p2 and r1 == q2:
            C[i][j] = 1

# A*B
def mul(a, b):
    c = [[0]*len(b[0]) for i in range(len(a))]
    for i in range(len(a)):
        for k in range(len(b)):
            for j in range(len(b[0])):
                c[i][j] = (c[i][j] + a[i][k]*b[k][j])%mod

    return c

#A**n
def pow(a, n):
    b = [[0]*len(a) for i in range(len(a))]
    for i in range(len(a)):
        b[i][i] = 1
    while n > 0:
        if n & 1 == 1:
            b = mul(a, b)
        a = mul(a, a)
        n = n>>1
    return b

#print(C)

B = mul(C, pow(A, n-4))
#print(B)
ans = 0
for i in range(m):
    p1, q1, r1 = PQR[i]
    if r1 == 0:
        for j in range(m):
            ans += B[j][i]
        ans %= mod
print(ans)
0