結果
| 問題 | No.1340 おーじ君をさがせ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-15 22:41:40 |
| 言語 | Python3 (3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 377 ms / 2,000 ms |
| + 231µs | |
| コード長 | 601 bytes |
| 記録 | |
| コンパイル時間 | 55 ms |
| コンパイル使用メモリ | 14,848 KB |
| 実行使用メモリ | 36,108 KB |
| 最終ジャッジ日時 | 2026-10-01 03:16:32 |
| 合計ジャッジ時間 | 23,836 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 59 |
ソースコード
import numpy as np
def pow_matrix_mod(x, n):
if not n:
return np.eye(len(x), dtype=int)
if n % 2 == 0:
return pow_matrix_mod(np.where((x @ x) != 0, 1, 0), n // 2)
else:
tmp = pow_matrix_mod(np.where((x @ x) != 0, 1, 0), (n - 1) // 2)
return np.where((x @ tmp) != 0, 1, 0)
N, M, T = map(int, input().split())
matr = [[0] * N for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
matr[a][b] = 1
matr = np.array(matr)
first = np.zeros(N, dtype=int)
first[0] = 1
ans = np.count_nonzero(first @ pow_matrix_mod(matr, T))
print(ans)