結果
| 問題 | No.681 Fractal Gravity Glue |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-28 00:15:28 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,476 bytes |
| 記録 | |
| コンパイル時間 | 2,178 ms |
| コンパイル使用メモリ | 194,972 KB |
| 最終ジャッジ日時 | 2025-01-05 10:27:17 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 RE * 5 MLE * 3 |
ソースコード
#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;
auto rec = fix([&](auto&& self) {
int ind = 0;
ll H = D + 1;
for (; H - 1 <= rest; ind++, H *= (D + 1)) {
}
if (ind == 0) {
ans += rest;
return;
}
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;
}
self(self);
});
rec();
cout << (stone[B - 1] + MOD - ans) % MOD << endl;
return 0;
}