結果

問題 No.93 ペガサス
コンテスト
ユーザー szkhts
提出日時 2026-03-26 10:42:16
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 872 ms / 5,000 ms
コード長 960 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 899 ms
コンパイル使用メモリ 20,796 KB
実行使用メモリ 35,080 KB
最終ジャッジ日時 2026-03-26 10:42:41
合計ジャッジ時間 15,958 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
import numpy as np
MOD = 10 ** 9 + 7

N = int(input())
if N == 1:
    print(1)
    exit()

M = N // 2


def update_dp(f, g):
    newf = np.zeros(len(f) + 1, np.int64)
    newg = newf.copy()
    newg[:-1] = f + f + g
    newf[1:] = f + g
    newf %= MOD
    newg %= MOD
    return newf, newg


f = np.array([0, 1], np.int64)
g = np.array([0, 0], np.int64)

for _ in range((N - 2) // 2):
    f, g = update_dp(f, g)

A = f + g

if N & 1:
    f, g = update_dp(f, g)
B = f + g


def convolve(A, B):
    A1, A2 = divmod(A, 1 << 16)
    B1, B2 = divmod(B, 1 << 16)
    X = np.convolve(A1, B1) % MOD
    Z = np.convolve(A2, B2) % MOD
    Y = (np.convolve(A1 + A2, B1 + B2) - X - Z) % MOD
    return ((X << 32) + (Y << 16) + Z) % MOD


A = convolve(A, B)
fact = [1, 1]
for n in range(2, N + 10):
    fact.append(fact[-1] * n % MOD)
fact = np.array(fact, dtype=np.int64)

A *= fact[:N+1]
A[1 - (N & 1)::2] *= - 1
A %= MOD
answer = A.sum() % MOD
print(answer)
0