結果

問題 No.1340 おーじ君をさがせ
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-03-10 10:47:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,710 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 86,712 KB
実行使用メモリ 86,876 KB
最終ジャッジ日時 2023-10-12 12:51:51
合計ジャッジ時間 6,122 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
77,544 KB
testcase_01 AC 106 ms
72,132 KB
testcase_02 AC 111 ms
72,128 KB
testcase_03 AC 111 ms
72,236 KB
testcase_04 AC 113 ms
72,220 KB
testcase_05 AC 110 ms
72,056 KB
testcase_06 AC 109 ms
72,296 KB
testcase_07 AC 110 ms
72,188 KB
testcase_08 AC 107 ms
71,956 KB
testcase_09 AC 109 ms
72,132 KB
testcase_10 AC 157 ms
77,628 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
import sys
input = sys.stdin.buffer.readline
from functools import reduce
##fの単位元を要考慮、matrix_powのCの初期化

def f(x,y):
    return x|y
def g(x,y):
    return x&y
def matrix_mul(A,B,f,g,mod = None):
    nA = len(A)
    mA = len(A[0])
    mB = len(B[0])
    
    tmp = [[0]*mB for _ in range(nA)]
    
    if mod is None:
        for i in range(nA):
            for j in range(mB):
                tmp[i][j] = reduce(f,(g(A[i][k],B[k][j]) for k in range(mA)))
                
        return tmp
    
    for i in range(nA):
        for j in range(mB):
            tmp[i][j] = reduce(f,(g(A[i][k],B[k][j])%mod for k in range(mA)))%mod
    return tmp
    

def matrix_pow(A,n,f,g,mod = None):
    nbit = list(str(bin(n))[2:])
    nbit = [int(i) for i in nbit]
    N = len(A)
    C = [[False]*N for _ in range(N)]
    B = A
    for i in range(N):
        C[i][i] = True
        
    if mod is None:
        if f is None:
            for i in range(len(nbit)):
                if nbit[-1-i] == 1:
                    C = matrix_mul(C,B,f,g)
                
                B = matrix_mul(B,B,f,g)
            return C
        
    for i in range(len(nbit)):
        if nbit[-1-i] == 1:
            C = matrix_mul(C,B,f,g,mod=mod)
        
        B = matrix_mul(B,B,f,g,mod=mod)
    
    return C
    
N,M,T = map(int,input().split())
A = [[False]*N for _ in range(N)]

for _ in range(M):
    a,b = map(int,input().split())
    A[b][a] = True

INIT = [[False] for _ in range(N)]
INIT[0] = [True]

X = matrix_pow(A,T,f,g)
Y = matrix_mul(X,INIT,f,g)
ans = sum(int(*Y[i]) for i in range(N))
#print(*Y[0])
print(ans)
        
        
0