結果

問題 No.2156 ぞい文字列
ユーザー terasaterasa
提出日時 2022-12-09 22:06:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 80,228 KB
最終ジャッジ日時 2023-08-04 23:48:55
合計ジャッジ時間 4,664 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
79,948 KB
testcase_01 AC 165 ms
79,944 KB
testcase_02 AC 175 ms
80,004 KB
testcase_03 AC 162 ms
80,032 KB
testcase_04 AC 162 ms
79,988 KB
testcase_05 AC 163 ms
79,968 KB
testcase_06 AC 161 ms
80,120 KB
testcase_07 AC 164 ms
80,092 KB
testcase_08 AC 169 ms
79,952 KB
testcase_09 AC 165 ms
79,988 KB
testcase_10 AC 163 ms
79,996 KB
testcase_11 AC 164 ms
80,072 KB
testcase_12 AC 164 ms
80,116 KB
testcase_13 AC 167 ms
80,216 KB
testcase_14 AC 163 ms
79,944 KB
testcase_15 AC 162 ms
80,084 KB
testcase_16 AC 163 ms
80,084 KB
testcase_17 AC 165 ms
80,000 KB
testcase_18 AC 161 ms
80,200 KB
testcase_19 AC 162 ms
80,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import List, Tuple, Callable, TypeVar, Optional
import sys
import itertools
import heapq
import bisect
import math
from collections import deque, defaultdict
from functools import lru_cache, cmp_to_key

input = sys.stdin.readline

if __file__ != 'prog.py':
    sys.setrecursionlimit(10 ** 6)


def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input()[:-1]


class Matpow:
    def __init__(self, A, mod, digit=60):
        self.A = A
        self.N = len(A)
        self.mod = mod
        self.digit = digit
        self.doubling = [None] * self.digit

        self.doubling[0] = A
        for i in range(1, self.digit):
            self.doubling[i] = self.mul(self.doubling[i - 1], self.doubling[i - 1])

    def pow(self, n):
        E = [[1 if i == j else 0 for j in range(self.N)] for i in range(self.N)]
        acc = E
        for k in range(self.digit):
            if n & (1 << k):
                acc = self.mul(acc, self.doubling[k])
        return acc

    def mul(self, A, B):
        C = [[0 for _ in range(self.N)] for _ in range(self.N)]
        for i in range(self.N):
            for j in range(self.N):
                for k in range(self.N):
                    C[i][j] += A[i][k] * B[k][j]
                    C[i][j] %= self.mod
        return C


N = int(input())
mod = 998244353

A = [[1, 1],
     [1, 0]]
An = Matpow(A, mod).pow(N - 1)
ans = (sum(An[0]) - 1) % mod
print(ans)
0