結果

問題 No.840 ほむほむほむら
ユーザー tempura_pptempura_pp
提出日時 2019-03-29 18:57:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,055 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 95,616 KB
最終ジャッジ日時 2024-04-24 16:42:31
合計ジャッジ時間 23,661 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
60,032 KB
testcase_01 AC 53 ms
60,928 KB
testcase_02 AC 71 ms
64,256 KB
testcase_03 AC 187 ms
71,040 KB
testcase_04 AC 51 ms
60,544 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 TLE -
testcase_20 AC 43 ms
52,224 KB
testcase_21 AC 50 ms
60,160 KB
testcase_22 AC 65 ms
63,360 KB
testcase_23 TLE -
testcase_24 WA -
testcase_25 AC 50 ms
59,648 KB
testcase_26 AC 70 ms
64,000 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def mul(A, B) :
    N=len(A)
    mod=1000000007
    C=[[0 for i in range(N)] for j in range(N)]
    for i in range (N) : 
        for j in range(N) : 
            for k in range(N) :
                C[i][j]+=A[i][k]*B[k][j]
            C[i][j]%=mod
    return C

def powmat(A, n) :
    N=len(A)
    C=[[0 for i in range(N)] for j in range(N)]
    for i in range(N) : C[i][i] = 1
    while n > 0 :
        if n%2==1 : C = mul(C,A)
        A=mul(A,A)
        n>>=1
    return C

def solve() : 
    N, K = map(int,input().split())
    mod = 1000000007
    M = K**3
    A = [[0 for i in range(M)] for j in range(M)]
    for i in range(K) :
        for j in range(K) :
            for k in range(K) :
                cur=i*K*K+j*K+k;
                nxt1=i*K*K+j*K+(k+1)%K;
                nxt2=i*K*K+(j+k)%K*K+k;
                nxt3=(i+j)%K*K*K+j*K+k;
                A[nxt1][cur]+=1
                A[nxt2][cur]+=1
                A[nxt3][cur]+=1
    C = powmat(A, N)
    ans = 0
    for i in range(K*K) : 
        ans += C[0][i]
    print(ans%mod)

solve()
0