結果

問題 No.314 ケンケンパ
ユーザー irumo8202irumo8202
提出日時 2022-01-30 15:16:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 510 ms / 1,000 ms
コード長 385 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 48,652 KB
最終ジャッジ日時 2023-09-02 01:38:46
合計ジャッジ時間 5,855 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 510 ms
29,600 KB
testcase_01 AC 123 ms
29,568 KB
testcase_02 AC 121 ms
29,572 KB
testcase_03 AC 122 ms
29,704 KB
testcase_04 AC 120 ms
29,588 KB
testcase_05 AC 120 ms
29,576 KB
testcase_06 AC 118 ms
29,596 KB
testcase_07 AC 119 ms
29,576 KB
testcase_08 AC 119 ms
29,740 KB
testcase_09 AC 119 ms
29,612 KB
testcase_10 AC 119 ms
29,640 KB
testcase_11 AC 118 ms
29,656 KB
testcase_12 AC 118 ms
29,676 KB
testcase_13 AC 118 ms
29,668 KB
testcase_14 AC 122 ms
29,548 KB
testcase_15 AC 120 ms
29,536 KB
testcase_16 AC 119 ms
29,576 KB
testcase_17 AC 119 ms
29,576 KB
testcase_18 AC 119 ms
29,592 KB
testcase_19 AC 120 ms
48,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

MOD = 10 ** 9 + 7

M = np.array([[0, 0, 1], [1, 0, 0], [1, 1, 0]])

doubling = [M]
for i in range(20):
    doubling.append(doubling[-1] @ doubling[-1])
    doubling[-1] = np.mod(doubling[-1], MOD)


N = int(input()) - 1
V = np.array([1, 0, 0])

for i in range(20)[::-1]:
    if N >> i & 1:
        V = doubling[i] @ V
        V = np.mod(V, MOD)

print(sum(V) % MOD)
0