結果

問題 No.1073 無限すごろく
ユーザー ayaoniayaoni
提出日時 2020-11-28 17:43:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 77,552 KB
最終ジャッジ日時 2023-10-10 00:48:06
合計ジャッジ時間 5,916 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,308 KB
testcase_01 AC 81 ms
71,300 KB
testcase_02 AC 89 ms
75,784 KB
testcase_03 AC 82 ms
71,476 KB
testcase_04 AC 80 ms
71,304 KB
testcase_05 AC 76 ms
71,504 KB
testcase_06 AC 78 ms
71,648 KB
testcase_07 AC 81 ms
71,140 KB
testcase_08 AC 80 ms
71,636 KB
testcase_09 AC 79 ms
71,364 KB
testcase_10 AC 84 ms
76,044 KB
testcase_11 AC 83 ms
75,824 KB
testcase_12 AC 82 ms
75,844 KB
testcase_13 AC 89 ms
75,892 KB
testcase_14 AC 88 ms
75,944 KB
testcase_15 AC 87 ms
76,020 KB
testcase_16 AC 94 ms
75,780 KB
testcase_17 AC 92 ms
75,984 KB
testcase_18 AC 90 ms
75,812 KB
testcase_19 AC 92 ms
76,168 KB
testcase_20 AC 92 ms
75,920 KB
testcase_21 AC 98 ms
76,768 KB
testcase_22 AC 90 ms
75,924 KB
testcase_23 AC 106 ms
76,620 KB
testcase_24 AC 104 ms
76,584 KB
testcase_25 AC 106 ms
76,824 KB
testcase_26 AC 104 ms
76,648 KB
testcase_27 AC 103 ms
76,800 KB
testcase_28 AC 110 ms
77,388 KB
testcase_29 AC 111 ms
77,472 KB
testcase_30 AC 111 ms
77,468 KB
testcase_31 AC 110 ms
77,552 KB
testcase_32 AC 107 ms
77,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())


def matrix_multiplication_mod(A,B,p):
    l = len(A)
    m = len(B)
    n = len(B[0])
    C = [[0]*n for _ in range(l)]
    for i in range(l):
        for j in range(n):
            C[i][j] = sum((A[i][k]*B[k][j]) % p for k in range(m)) % p
    return C


def matrix_power_mod(A,n,p):
    l = len(A)
    C = [[0] * l for _ in range(l)]
    for i in range(l):
        C[i][i] = 1
    while n > 0:
        if n % 2 == 1:
            C = matrix_multiplication_mod(C,A,p)
        A = matrix_multiplication_mod(A,A,p)
        n >>= 1
    return C


N = I()
mod = 10**9+7

a = pow(6,mod-2,mod)

P = [1,a]
for _ in range(4):
    P.append((P[-1]*7*a) % mod)

if N <= 5:
    print(P[N])
    exit()

A = [[a,a,a,a,a,a],[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0],[0,0,0,1,0,0],[0,0,0,0,1,0,]]
X = matrix_power_mod(A,N-5,mod)[0]
P.reverse()

ans = 0
for x,p in zip(X,P):
    ans += x*p
    ans %= mod

print(ans)
0