結果

問題 No.533 Mysterious Stairs
コンテスト
ユーザー cologne
提出日時 2025-12-18 15:58:58
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 301 ms / 5,000 ms
コード長 902 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 399 ms
コンパイル使用メモリ 82,644 KB
実行使用メモリ 187,156 KB
最終ジャッジ日時 2025-12-18 15:59:04
合計ジャッジ時間 4,659 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import string
import sys
from typing import Generator, List, Tuple


def input(): return sys.stdin.readline().rstrip('\n')


def main():
    M = 10 ** 9 + 7
    n = int(input())
    d = [(0, 0, 0)] * (n + 1)
    for i in range(1, n + 1):
        a = 1 if i == 1 else 0
        b = 1 if i == 2 else 0
        c = 1 if i == 3 else 0
        if i >= 1:
            a += d[i - 1][1] + d[i - 1][2]
        if i >= 2:
            b += d[i - 2][0] + d[i - 2][2]
        if i >= 3:
            c += d[i - 3][0] + d[i - 3][1]
        d[i] = (a % M, b % M, c % M)

    return sum(d[-1]) % M


if __name__ == '__main__':
    ret = main()


    def out(x):
        if isinstance(x, List) or isinstance(x, Tuple):
            print(*x)
        else:
            print(x)


    if ret is None:
        pass
    elif isinstance(ret, Generator):
        for val in ret:
            out(val)
    else:
        out(ret)
0