結果
問題 | No.572 妖精の演奏 |
ユーザー |
![]() |
提出日時 | 2021-04-23 12:14:19 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 267 ms / 2,000 ms |
コード長 | 704 bytes |
コンパイル時間 | 134 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-07-04 06:59:37 |
合計ジャッジ時間 | 2,481 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
import sysinput = sys.stdin.readlinedef matmul(A, B):sz = len(A)res = [[0]*sz for _ in range(sz)]for i in range(sz):for j in range(sz):for k in range(sz):res[i][j] = max(res[i][j], A[i][k]+B[k][j])return resN = int(input())M = int(input())A = list(list(map(int,input().split())) for _ in range(M))D = N.bit_length()mat = [-1]*Dmat[0] = Afor i in range(1, D):mat[i] = matmul(mat[i-1],mat[i-1])dp = [0]*MN -= 1for d in reversed(range(D)):if (N>>d)&1:ndp = [0]*Mfor i in range(M):for j in range(M):ndp[j] = max(ndp[j], dp[i] + mat[d][i][j])dp = ndpprint(max(dp))