結果

問題 No.492 IOI数列
ユーザー rlangevinrlangevin
提出日時 2023-07-12 12:33:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 1,000 ms
コード長 755 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,376 KB
実行使用メモリ 75,576 KB
最終ジャッジ日時 2023-10-12 02:41:27
合計ジャッジ時間 3,415 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,312 KB
testcase_01 AC 82 ms
75,552 KB
testcase_02 AC 82 ms
75,576 KB
testcase_03 AC 80 ms
74,836 KB
testcase_04 AC 75 ms
71,308 KB
testcase_05 AC 76 ms
71,376 KB
testcase_06 AC 80 ms
74,996 KB
testcase_07 AC 81 ms
75,364 KB
testcase_08 AC 79 ms
74,932 KB
testcase_09 AC 78 ms
75,032 KB
testcase_10 AC 75 ms
71,200 KB
testcase_11 AC 76 ms
71,212 KB
testcase_12 AC 74 ms
71,192 KB
testcase_13 AC 74 ms
71,268 KB
testcase_14 AC 76 ms
71,196 KB
testcase_15 AC 75 ms
71,216 KB
testcase_16 AC 75 ms
71,408 KB
testcase_17 AC 75 ms
71,196 KB
testcase_18 AC 76 ms
71,356 KB
testcase_19 AC 76 ms
71,436 KB
testcase_20 AC 75 ms
71,068 KB
testcase_21 AC 76 ms
71,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def Matprod(A, B, mod, N):
    temp = [0] * N*N
    for i in range(N):
        for j in range(N):
            ij = i * N + j
            for k in range(N):
                temp[ij] += A[i*N+k] * B[k*N+j]
                temp[ij] %= mod
    return temp

def Matpow_Linear(A, M, mod, N):
    Mat = [0] * N*N
    for i in range(N):
        Mat[i*N+i] = 1
         
    while M:
        if M & 1:
            Mat = Matprod(Mat, A, mod, N)
        A = Matprod(A, A, mod, N)
        M >>= 1
    return Mat  


N = int(input())
mod1 = 10 ** 9 + 7
mod2 = 101010101010101010101

A = [100, 1, 0, 1]
A1 = Matpow_Linear(A, N-1, mod1, 2)
A2 = Matpow_Linear(A, N-1, mod2, 2)
print((A1[0] + A1[1])%mod1)
print((A2[0] + A2[1])%mod2)
0