結果

問題 No.681 Fractal Gravity Glue
ユーザー PachicobuePachicobue
提出日時 2018-04-28 00:18:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,452 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 200,808 KB
実行使用メモリ 814,724 KB
最終ジャッジ日時 2023-09-10 07:32:45
合計ジャッジ時間 4,216 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 RE -
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }

int main()
{
    ll N, B, D;
    cin >> N >> B >> D;
    vector<ll> stone(B);
    stone[0] = D;
    for (int i = 1; i < B; i++) {
        stone[i] = (stone[i - 1] * (D + 1) % MOD + D * (i + 1) % MOD) % MOD;
    }
    ll ans = 0;
    ll rest = N;
    while (rest > 0) {
        int ind = 0;
        ll H = D + 1;
        for (; H - 1 <= rest; ind++, H *= (D + 1)) {
        }
        if (ind == 0) {
            ans += rest;
            rest = 0;
            continue;
        }
        const ll h = H / (D + 1);
        const ll sub = (stone[ind - 1] + (ind + 1)) % MOD;
        const ll rep = rest / h;
        rest = rest % h;
        (ans += rep * sub % MOD) %= MOD;
        if (rest == h - 1) {
            (ans += stone[ind - 1]) %= MOD;
            rest = 0;
        }
    }
    cout << (stone[B - 1] + MOD - ans) % MOD << endl;

    return 0;
}
0