結果
| 問題 |
No.1011 Infinite Stairs
|
| コンテスト | |
| ユーザー |
imoni_kawaii
|
| 提出日時 | 2020-06-12 13:35:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 124 ms / 2,000 ms |
| コード長 | 2,855 bytes |
| コンパイル時間 | 2,846 ms |
| コンパイル使用メモリ | 196,876 KB |
| 最終ジャッジ日時 | 2025-01-11 01:47:44 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }
constexpr int MAX_N = 2010101;
constexpr int MOD = 1e9+7;
//constexpr int MOD = 998244353;
struct mint {
long long x;
mint(long long x = 0) noexcept : x((x%MOD + MOD) % MOD) {}
// basis
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) noexcept { if((x += a.x) >= MOD) x -= MOD; return *this; }
mint& operator-=(const mint a) noexcept { if((x += MOD-a.x) >= MOD) x -= MOD; return *this; }
mint& operator*=(const mint a) noexcept { (x *= a.x) %= MOD; return *this; }
mint operator+(const mint a) const noexcept { return mint(*this) += a; }
mint operator-(const mint a) const noexcept { return mint(*this) -= a; }
mint operator*(const mint a) const noexcept { return mint(*this) *= a; }
mint mpow(long long t) const noexcept {
if(!t) return 1;
mint a = mpow(t>>1);
a *= a;
if(t&1) a *= *this;
return a;
}
// for prime MOD
mint inv() const noexcept { return mpow(MOD-2); }
mint& operator/=(const mint a) noexcept { return *this *= a.inv(); }
mint operator/(const mint a) const noexcept { return mint(*this) /= a; }
// comparison
bool operator==(const mint &a) const noexcept { return this->x == a.x; }
bool operator!=(const mint &a) const noexcept { return this->x != a.x; }
// I/O stream
friend istream& operator>>(istream& is, mint& a) noexcept { return is >> a.x; }
friend ostream& operator<<(ostream& os, const mint& a) noexcept { return os << a.x; }
};
// additional
mint mpow(const long long &a, ll n) noexcept { return mint(a).mpow(n); }
mint mpow(const mint &a, ll n) noexcept { return a.mpow(n); }
struct combination {
vector<mint> fac, ifac;
combination(int n) : fac(n+1), ifac(n+1) {
assert(n < MOD);
fac[0] = 1;
for(int i = 1; i <= n; ++i) fac[i] = fac[i-1]*i;
ifac[n] = fac[n].inv();
for(int i = n; i >= 1; --i) ifac[i-1] = ifac[i]*i;
}
mint operator()(int n, int k) {
if(k < 0 || k > n) return 0;
return fac[n]*ifac[k]*ifac[n-k];
}
} com(MAX_N);
mint fac(int n) { assert(0 <= n && n <= MAX_N); return com.fac[n]; }
mint ifac(int n) { assert(0 <= n && n <= MAX_N); return com.ifac[n]; }
int main() {
cin.tie(0); ios::sync_with_stdio(false);
ll n, d, k;
cin >> n >> d >> k;
mint ans = 0;
rep(i, n+1) {
ans += mpow(-1, i)*com(n, i)*com(k-d*i-1, n-1);
}
cout << ans << '\n';
return 0;
}
imoni_kawaii