結果

問題 No.1340 おーじ君をさがせ
ユーザー ygd.ygd.
提出日時 2021-01-17 00:40:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,605 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 82,400 KB
最終ジャッジ日時 2023-08-19 03:03:00
合計ジャッジ時間 28,670 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,252 KB
testcase_01 AC 70 ms
71,260 KB
testcase_02 AC 65 ms
71,504 KB
testcase_03 AC 65 ms
71,280 KB
testcase_04 AC 65 ms
71,160 KB
testcase_05 AC 63 ms
71,200 KB
testcase_06 AC 63 ms
71,176 KB
testcase_07 AC 66 ms
71,284 KB
testcase_08 AC 72 ms
71,444 KB
testcase_09 AC 66 ms
71,280 KB
testcase_10 AC 79 ms
76,400 KB
testcase_11 AC 351 ms
77,008 KB
testcase_12 AC 118 ms
76,508 KB
testcase_13 AC 423 ms
78,568 KB
testcase_14 AC 694 ms
77,116 KB
testcase_15 AC 574 ms
77,040 KB
testcase_16 AC 111 ms
76,408 KB
testcase_17 AC 239 ms
76,912 KB
testcase_18 AC 373 ms
77,028 KB
testcase_19 AC 89 ms
76,300 KB
testcase_20 AC 78 ms
76,288 KB
testcase_21 AC 383 ms
77,740 KB
testcase_22 AC 1,377 ms
82,400 KB
testcase_23 AC 382 ms
77,736 KB
testcase_24 AC 1,605 ms
78,496 KB
testcase_25 AC 122 ms
77,688 KB
testcase_26 AC 113 ms
77,764 KB
testcase_27 AC 104 ms
77,528 KB
testcase_28 AC 134 ms
77,480 KB
testcase_29 AC 94 ms
77,368 KB
testcase_30 AC 406 ms
77,788 KB
testcase_31 AC 1,587 ms
78,648 KB
testcase_32 AC 1,491 ms
78,044 KB
testcase_33 AC 1,455 ms
78,256 KB
testcase_34 AC 1,325 ms
78,200 KB
testcase_35 AC 1,573 ms
78,328 KB
testcase_36 AC 66 ms
71,480 KB
testcase_37 AC 88 ms
77,340 KB
testcase_38 AC 1,568 ms
78,312 KB
testcase_39 AC 455 ms
77,536 KB
testcase_40 AC 496 ms
77,784 KB
testcase_41 AC 482 ms
77,920 KB
testcase_42 AC 70 ms
76,344 KB
testcase_43 AC 72 ms
76,348 KB
testcase_44 AC 72 ms
76,312 KB
testcase_45 AC 76 ms
76,212 KB
testcase_46 AC 375 ms
77,832 KB
testcase_47 AC 400 ms
78,076 KB
testcase_48 AC 428 ms
77,612 KB
testcase_49 AC 412 ms
77,204 KB
testcase_50 AC 416 ms
77,204 KB
testcase_51 AC 416 ms
77,216 KB
testcase_52 AC 728 ms
77,348 KB
testcase_53 AC 715 ms
77,080 KB
testcase_54 AC 723 ms
77,528 KB
testcase_55 AC 597 ms
78,228 KB
testcase_56 AC 74 ms
76,012 KB
testcase_57 AC 74 ms
76,360 KB
testcase_58 AC 65 ms
71,396 KB
testcase_59 AC 269 ms
76,572 KB
testcase_60 AC 67 ms
71,152 KB
testcase_61 AC 272 ms
76,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mat_dot(A, B, MOD=pow(10,9)+7):
  #A:n*m行列, B:m*l行列
  n, m, l = len(A), len(A[0]), len(B[0])
  X = [[0]*l for i in range(n)]
  for i in range(n):
    for j in range(l):
      temp = 0
      for k in range(m):
        temp = (temp|(A[i][k]&B[k][j])) % MOD
      X[i][j] = temp
  return X
 
def mat_pow(A, x, MOD=pow(10,9)+7):
  #A^x
  n = len(A)
  X = [[0] * n for i in range(n)]
  for i in range(n):
    X[i][i] = 1
  for i in range(x.bit_length()):
    if (x>>i)&1:
      X = mat_dot(X, A, MOD)
    A = mat_dot(A, A, MOD)
  return X

N,M,T = map(int,input().split())
A = [[0]*N for _ in range(N)] 
for i in range(M):
    a,b = map(int,input().split())
    A[b][a] = 1
#print(A)
AT = mat_pow(A,T)
I = [[0] for _ in range(N)]
#print(I)
I[0][0] = 1
#print(AT)
ANS = mat_dot(AT,I)
#print(ANS)
ret = 0
for x in ANS:
    for y in x:
        ret += y
print(ret)
0