結果

問題 No.1331 Moving Penguin
ユーザー LyricalMaestro
提出日時 2025-01-14 00:03:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 945 ms / 1,500 ms
コード長 822 bytes
コンパイル時間 1,728 ms
コンパイル使用メモリ 81,408 KB
実行使用メモリ 91,264 KB
最終ジャッジ日時 2025-01-14 00:04:14
合計ジャッジ時間 38,992 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1331

import math

MOD = 10 ** 9 + 7    

def main():
    N = int(input())
    A = list(map(int, input().split()))

    dp = [0] * (N + 1)
    dp[1] = 1

    sqrt_n = int(math.sqrt(N))
    mods = [[0] * (max(1, a)) for a in range(sqrt_n + 1)]
    for p in range(1, N + 1):
        a = A[p - 1]
        for n in range(1, sqrt_n + 1):
            dp[p] += mods[n][p % n]
            dp[p] %= MOD

        if p < N and a > 1:
            dp[p + 1] += dp[p]
            dp[p + 1] %= MOD

        if a > sqrt_n:
            x = p + a
            while x <= N:
                dp[x] += dp[p]
                dp[x] %= MOD
                x += a
        else:
            mods[a][p % a] += dp[p]
            mods[a][p % a] %= MOD

    print(dp[-1])








if __name__ == "__main__":
    main()
0