結果
問題 | No.1011 Infinite Stairs |
ユーザー | shibh308 |
提出日時 | 2020-03-20 21:33:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,400 ms / 2,000 ms |
コード長 | 2,572 bytes |
コンパイル時間 | 2,290 ms |
コンパイル使用メモリ | 198,840 KB |
最終ジャッジ日時 | 2025-01-09 08:17:06 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = long long; const i64 MOD = 1e9 + 7; const i64 INF = i64(1e18) + 7; template <typename T> bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } template <typename T> bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template <i64 mod = MOD> struct ModInt{ i64 p; ModInt() : p(0){} ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;} ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;} ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;} ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;} ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;} ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;} ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;} ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;} ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;} friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){ stream << *x; return stream; } friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){ stream >> *x; return stream; } ModInt& operator++(){p = (p + 1) % mod; return *this;} ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;} bool operator==(const ModInt& y) const{return p == *y;} bool operator!=(const ModInt& y) const{return p != *y;} const i64& operator*() const{return p;} i64& operator*(){return p;} }; using mint = ModInt<>; template <typename T> struct BIT{ vector<T> elm; BIT(int n, T init = T()) : elm(n + 1, init){ } // [0, x) T sum(int x){ T val = 0; for(; x > 0; x -= x & -x) val += elm[x]; return val; } // [l, r) T sum(int l, int r){ return sum(r) - sum(l); } void add(int x, T val){ for(++x; x < elm.size(); x += x & -x) elm[x] += val; } }; signed main(){ int n, d, k; cin >> n >> d >> k; // セグ木じゃ通らないんかーい! vector<BIT<mint>> dp(n + 1, BIT<mint>(k + 1)); dp[0].add(0, 1); for(int i = 0; i < n; ++i) for(int j = 0; j <= k; ++j) dp[i + 1].add(j, dp[i].sum(max(0, j - d), j)); cout << dp.back().sum(k, k + 1) << endl; return 0; }