結果

問題 No.1340 おーじ君をさがせ
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-03-10 10:41:03
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,607 bytes
コンパイル時間 1,256 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 85,908 KB
最終ジャッジ日時 2023-10-12 12:45:40
合計ジャッジ時間 13,327 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
72,160 KB
testcase_01 AC 103 ms
72,348 KB
testcase_02 AC 104 ms
72,496 KB
testcase_03 AC 105 ms
72,660 KB
testcase_04 AC 104 ms
72,308 KB
testcase_05 AC 105 ms
72,208 KB
testcase_06 AC 106 ms
72,624 KB
testcase_07 AC 105 ms
72,416 KB
testcase_08 AC 104 ms
72,484 KB
testcase_09 AC 103 ms
72,416 KB
testcase_10 AC 140 ms
78,356 KB
testcase_11 AC 445 ms
80,816 KB
testcase_12 AC 235 ms
78,568 KB
testcase_13 AC 360 ms
80,084 KB
testcase_14 AC 744 ms
83,552 KB
testcase_15 AC 625 ms
82,132 KB
testcase_16 AC 224 ms
78,776 KB
testcase_17 AC 306 ms
79,748 KB
testcase_18 AC 437 ms
81,168 KB
testcase_19 AC 158 ms
78,416 KB
testcase_20 AC 147 ms
78,568 KB
testcase_21 AC 494 ms
81,980 KB
testcase_22 AC 1,007 ms
85,908 KB
testcase_23 AC 978 ms
81,800 KB
testcase_24 TLE -
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 #

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