結果

問題 No.572 妖精の演奏
ユーザー convexineqconvexineq
提出日時 2021-02-25 00:58:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 650 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 66,116 KB
最終ジャッジ日時 2023-10-25 06:20:03
合計ジャッジ時間 2,334 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
61,608 KB
testcase_01 AC 46 ms
61,608 KB
testcase_02 AC 43 ms
59,304 KB
testcase_03 AC 44 ms
59,308 KB
testcase_04 AC 48 ms
61,812 KB
testcase_05 AC 49 ms
63,864 KB
testcase_06 AC 47 ms
61,680 KB
testcase_07 AC 47 ms
61,608 KB
testcase_08 AC 47 ms
61,608 KB
testcase_09 AC 49 ms
63,852 KB
testcase_10 AC 52 ms
63,796 KB
testcase_11 AC 54 ms
63,796 KB
testcase_12 AC 54 ms
65,844 KB
testcase_13 AC 58 ms
66,116 KB
testcase_14 AC 50 ms
61,748 KB
testcase_15 AC 51 ms
61,748 KB
testcase_16 AC 50 ms
61,748 KB
testcase_17 AC 50 ms
61,748 KB
testcase_18 AC 46 ms
61,608 KB
testcase_19 AC 39 ms
53,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def matmul(A,B): # A,B: 行列
    res = [[0]*len(B[0]) for _ in range(len(A))]
    for i, resi in enumerate(res):
        for k, aik in enumerate(A[i]):
            for j,bkj in enumerate(B[k]):
                resi[j] = max(resi[j],aik+bkj)
    return res

def matpow(A,p): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1))
    elif p > 0:
        b = matpow(A,p//2)
        return matmul(b,b)
    else:
        return [[0 if i == j else -(1<<31) for j in range(len(A))] for i in range(len(A))]

n = int(input())
m = int(input())
a = [list(map(int,input().split())) for _ in range(m)]
r = matmul([[0]*m],matpow(a,n-1))
print(max(r[0]))
0