結果

問題 No.1073 無限すごろく
ユーザー shotoyooshotoyoo
提出日時 2021-07-03 18:37:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 86,656 KB
実行使用メモリ 76,376 KB
最終ジャッジ日時 2023-09-12 23:25:02
合計ジャッジ時間 5,073 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,348 KB
testcase_01 AC 70 ms
71,156 KB
testcase_02 AC 74 ms
76,108 KB
testcase_03 AC 71 ms
71,224 KB
testcase_04 AC 71 ms
71,276 KB
testcase_05 AC 72 ms
71,268 KB
testcase_06 AC 72 ms
71,228 KB
testcase_07 AC 75 ms
75,784 KB
testcase_08 AC 72 ms
71,124 KB
testcase_09 AC 75 ms
75,676 KB
testcase_10 AC 75 ms
75,552 KB
testcase_11 AC 75 ms
75,440 KB
testcase_12 AC 72 ms
75,772 KB
testcase_13 AC 75 ms
75,852 KB
testcase_14 AC 75 ms
76,152 KB
testcase_15 AC 76 ms
76,044 KB
testcase_16 AC 76 ms
75,988 KB
testcase_17 AC 79 ms
76,300 KB
testcase_18 AC 76 ms
76,080 KB
testcase_19 AC 76 ms
75,940 KB
testcase_20 AC 75 ms
76,144 KB
testcase_21 AC 77 ms
76,136 KB
testcase_22 AC 78 ms
76,212 KB
testcase_23 AC 80 ms
76,224 KB
testcase_24 AC 81 ms
76,376 KB
testcase_25 AC 78 ms
76,080 KB
testcase_26 AC 78 ms
76,016 KB
testcase_27 AC 76 ms
76,228 KB
testcase_28 AC 79 ms
76,064 KB
testcase_29 AC 76 ms
76,232 KB
testcase_30 AC 77 ms
76,168 KB
testcase_31 AC 78 ms
76,148 KB
testcase_32 AC 78 ms
76,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

### 行列積 matrix multiplication
### 繰り返し2乗法 kurikae
def mul(a,b):
    """行列a,bの積
    aかbがNone のとき、単位行列として扱う
    """
    if a is None:
        return b
    elif b is None:
        return a
    n,m = len(a), len(a[0])
    k,l = len(b), len(b[0])
    # k==m
    out = [[0]*l for _ in range(n)]
    for i in range(n):
        for j in range(l):
            for p in range(m):
                out[i][j] += a[i][p]*b[p][j]%M
                if out[i][j]>M:
                    out[i][j] -= M
    return out
def mul2(m,a):
    """行列と配列の積
    m : None のとき単位行列扱い
    """
    if m is None:
        return a
    k,l = len(m), len(m[0])
#     ll = len(a)
    ans = [0]*k
    for i in range(k):
        for j in range(l):
            ans[i] += m[i][j] * a[j] % M
            if ans[i]>M:
                ans[i] -= M
    return ans
def mulk(m, k):
    """a^kを求める
    """
    if k==0:
        return None
    ans = None
    tmp = m
    while k>0:
        if k&1:
            ans = mul(ans, tmp)
        tmp = mul(tmp, tmp)
        k = k>>1
    return ans

n = int(input())
M = 10**9+7
inv = pow(6, M-2, M)
a = [[0]*6 for _ in range(6)]
for i in range(6):
    a[0][i] = inv
    for j in range(6):
        if i>0 and j+1==i:
            a[i][j] = 1
b = mulk(a, n)
res = mul2(b, [1]+[0]*5)
ans = res[0]
print(ans%M)
0