結果

問題 No.1073 無限すごろく
ユーザー tktk_snsntktk_snsn
提出日時 2020-06-05 21:58:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 8,380 KB
最終ジャッジ日時 2023-08-22 15:22:19
合計ジャッジ時間 1,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,356 KB
testcase_01 AC 16 ms
8,332 KB
testcase_02 AC 18 ms
7,856 KB
testcase_03 AC 17 ms
8,336 KB
testcase_04 AC 17 ms
8,324 KB
testcase_05 AC 17 ms
8,220 KB
testcase_06 AC 16 ms
8,220 KB
testcase_07 AC 16 ms
8,256 KB
testcase_08 AC 16 ms
8,212 KB
testcase_09 AC 16 ms
8,256 KB
testcase_10 AC 16 ms
8,324 KB
testcase_11 AC 16 ms
8,236 KB
testcase_12 AC 16 ms
8,256 KB
testcase_13 AC 17 ms
8,256 KB
testcase_14 AC 18 ms
8,344 KB
testcase_15 AC 18 ms
8,224 KB
testcase_16 AC 18 ms
8,204 KB
testcase_17 AC 17 ms
8,228 KB
testcase_18 AC 17 ms
8,212 KB
testcase_19 AC 18 ms
8,380 KB
testcase_20 AC 18 ms
8,260 KB
testcase_21 AC 18 ms
8,332 KB
testcase_22 AC 18 ms
8,344 KB
testcase_23 AC 19 ms
8,316 KB
testcase_24 AC 19 ms
7,952 KB
testcase_25 AC 19 ms
7,800 KB
testcase_26 AC 19 ms
7,956 KB
testcase_27 AC 19 ms
7,796 KB
testcase_28 AC 21 ms
7,800 KB
testcase_29 AC 21 ms
7,896 KB
testcase_30 AC 20 ms
8,352 KB
testcase_31 AC 21 ms
7,800 KB
testcase_32 AC 22 ms
7,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def mat_mul(A, B):
    mod = 10 ** 9 + 7
    res = [[0]*6 for _ in range(6)]
    for i in range(6):
        for k in range(6):
            for j in range(6):
                res[i][j] += A[i][k] * B[k][j]
                res[i][j] %= mod
    return res


def mat_pow(A, n):
    mod = 10 ** 9 + 7
    res = [[0] * 6 for _ in range(6)]
    for i in range(6):
        res[i][i] = 1
    while n:
        if n & 1:
            res = mat_mul(res, A)
        A = mat_mul(A, A)
        n >>= 1
    return res


mod = 10 ** 9 + 7
N = int(input())

p = [1]
for i in range(5):
    tmp = sum(p) * pow(6, mod - 2, mod) % mod
    p.append(tmp)
if N < 6:
    print(p[N])
    exit()


A = [[0] * 6 for _ in range(6)]
for i in range(6):
    A[0][i] = p[1]
for i in range(1, 6):
    A[i][i-1] = 1
p.reverse()

An = mat_pow(A, N - 5)
ans = 0
for i in range(6):
    ans += p[i] * An[0][i]
    ans %= mod

print(ans)
0