結果

問題 No.1073 無限すごろく
ユーザー qumazakiqumazaki
提出日時 2020-06-06 03:19:45
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 795 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 82,000 KB
最終ジャッジ日時 2023-08-23 08:23:04
合計ジャッジ時間 6,692 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
76,752 KB
testcase_01 AC 94 ms
76,460 KB
testcase_02 AC 107 ms
77,508 KB
testcase_03 AC 97 ms
76,640 KB
testcase_04 AC 97 ms
76,544 KB
testcase_05 AC 96 ms
76,588 KB
testcase_06 AC 94 ms
76,592 KB
testcase_07 AC 95 ms
76,832 KB
testcase_08 AC 96 ms
76,628 KB
testcase_09 AC 95 ms
76,460 KB
testcase_10 AC 95 ms
76,540 KB
testcase_11 AC 94 ms
76,464 KB
testcase_12 AC 93 ms
76,644 KB
testcase_13 AC 98 ms
77,536 KB
testcase_14 AC 98 ms
77,268 KB
testcase_15 AC 97 ms
77,844 KB
testcase_16 AC 99 ms
77,500 KB
testcase_17 AC 99 ms
77,704 KB
testcase_18 AC 98 ms
77,464 KB
testcase_19 AC 100 ms
77,588 KB
testcase_20 AC 99 ms
77,712 KB
testcase_21 AC 101 ms
77,492 KB
testcase_22 AC 101 ms
77,588 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy

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

def mat_power(a,b):
    # aもbもm*m列の行列とする。
    m = 6
    res = [[0] *m for _ in range(m)]
    for i in range(m):
        for j in range(m):
            for k in range(m):
                res[i][j] += a[i][k] * b[k][j]
            res[i][j] %= mod

    return res

# x0 = [1,0,0,0,0,0]
a = [[0]*6 for _ in range(6)]
for i in range(6):
    a[0][i] = pow(6,mod-2,mod)

for i in range(5):
    a[i+1][i] = 1

a_exp = []
a_exp.append(a)
i = 1
while(2**i < 10**18):
    ai = mat_power(a_exp[-1],a_exp[-1])
    a_exp.append(copy.deepcopy(ai))
    i += 2

a_n = [[0]*6 for _ in range(6)]
for i in range(6):
    a_n[i][i] = 1

i = 0
while(n>0):
    if(n%2==1):
        a_n = mat_power(a_n,a_exp[i])
    i += 1
    n //= 2

print(a_n[0][0])
0