結果

問題 No.3457 Fibo-shrink
コンテスト
ユーザー tetra4
提出日時 2026-02-28 14:03:45
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 896 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,614 ms
コンパイル使用メモリ 346,100 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-02-28 14:03:57
合計ジャッジ時間 5,857 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;

using ll = long long;
[[maybe_unused]] constexpr ll INF = (1LL << 60) - 1;
using mint = static_modint<10007>;

void solve() {
    ll k, s, n;
    cin >> k >> s >> n;
    vector<optional<mint>> f(n, nullopt);
    f[0] = 1, f[1] = 1;

    auto fib = [&](auto self, ll n) -> mint {
        if (f[n] == nullopt) f[n] = self(self, n - 1) + self(self, n - 2);
        return *f[n];
    };

    vector<mint> val(n, 0);
    val[0] = s;
    for (ll i = 1; i < n; ++i) {
        ll l = max(i - k - 1, 0ll);
        for (ll j = l; j < i; ++j) {
            val[i] += val[j] / fib(fib, i - j - 1);
        }
    }
    cout << val[n - 1].val() << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
0