結果
問題 | No.1750 ラムドスウイルスの感染拡大-hard |
ユーザー |
|
提出日時 | 2021-11-20 01:32:54 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 627 ms / 2,000 ms |
コード長 | 715 bytes |
コンパイル時間 | 344 ms |
コンパイル使用メモリ | 12,160 KB |
実行使用メモリ | 32,076 KB |
最終ジャッジ日時 | 2025-01-02 05:25:05 |
合計ジャッジ時間 | 18,032 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
from collections import defaultdict import numpy as np N, M, T = map(int, input().split()) A = np.zeros(shape=(N, N), dtype=np.int64) for _ in range(M): s, t = map(int, input().split()) A[s, t] = 1 A[t, s] = 1 mod = 998244353 def mat_mul(A, B, MOD): A1, A2 = A >> 15, A & (1 << 15) - 1 B1, B2 = B >> 15, B & (1 << 15) - 1 AB1 = np.dot(A1, B1) % MOD AB2 = np.dot(A2, B2) AB3 = np.dot(A1+A2, B1+B2) - AB1 - AB2 return ((AB1 << 30) + (AB3 << 15) + AB2) % MOD def mat_pow(A, K): P = np.eye(len(A), dtype=np.int64) while K: if K & 1: P = mat_mul(A, P, mod) A = mat_mul(A, A, mod) K >>= 1 return P P = mat_pow(A, T) print(P[0, 0])