結果

問題 No.1011 Infinite Stairs
ユーザー kcvlexkcvlex
提出日時 2020-03-20 21:52:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 892 ms / 2,000 ms
コード長 5,210 bytes
コンパイル時間 1,488 ms
コンパイル使用メモリ 168,004 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 10:56:38
合計ジャッジ時間 8,486 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 24 ms
4,376 KB
testcase_03 AC 581 ms
4,376 KB
testcase_04 AC 892 ms
4,380 KB
testcase_05 AC 890 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 101 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 31 ms
4,376 KB
testcase_11 AC 355 ms
4,376 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 AC 188 ms
4,376 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 122 ms
4,376 KB
testcase_16 AC 617 ms
4,376 KB
testcase_17 AC 652 ms
4,380 KB
testcase_18 AC 257 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 24 ms
4,376 KB
testcase_21 AC 139 ms
4,376 KB
testcase_22 AC 547 ms
4,380 KB
testcase_23 AC 131 ms
4,380 KB
testcase_24 AC 130 ms
4,376 KB
testcase_25 AC 253 ms
4,380 KB
testcase_26 AC 65 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t ...Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t ...Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

namespace tree {

template <typename T>
struct BIT {
    vec<T> data;
    T id_ele;

    BIT(ll size, T id_ele) : id_ele(id_ele) {
        ll bsize = 1;
        while (bsize < size) bsize *= 2;
        data = vec<T>(bsize + 1, id_ele);
    }

    T sum(ll pos) {
        T ret = id_ele;
        for (; 0 < pos; pos -= pos & -pos) ret += data[pos];
        return ret;
    }

    T sum(ll l, ll r) { return sum(r) - sum(l); }

    void add(ll pos, T delta) {
        for (++pos; pos < data.size(); pos += pos & -pos) data[pos] += delta;
    }
};

}

namespace math {

template <typename T>
constexpr T pow(const T &n, ll k) {
    T ret = n.mul_id_ele();
    T cur = n;
    while (k) {
        if (k & 1) ret *= cur;
        cur *= cur;
        k /= 2;
    }
    return ret;
}

}

namespace math {

template <ll Mod>
struct Modint {

    constexpr Modint(ll x) : x((Mod + x % Mod) % Mod) { }
    
    constexpr Modint() : Modint(0) { }
    
    constexpr Modint<Mod> add_id_ele() const { 
        return Modint<Mod>(0); 
    }
    
    constexpr Modint<Mod> mul_id_ele() const {
        return Modint<Mod>(1); 
    }
    
    constexpr ll& value() { 
        return x; 
    }
    
    constexpr ll value() const {
        return x; 
    }

    constexpr Modint& operator +=(const Modint &oth) {
        x += oth.value();
        if (Mod <= x) x -= Mod;
        return *this;
    }

    constexpr Modint& operator -=(const Modint &oth) {
        x += Mod - oth.value();
        if (Mod <= x) x -= Mod;
        return *this;
    }

    constexpr Modint& operator *=(const Modint &oth) {
        x *= oth.value();
        x %= Mod;
        return *this;
    }

    constexpr Modint& operator /=(const Modint &oth) {
        x *= oth.inv();
        x %= Mod;
        return *this;
    }

    constexpr Modint operator +(const Modint &oth) const {
        return Modint(x) += oth;
    }

    constexpr Modint operator -(const Modint &oth) const {
        return Modint(x) -= oth;
    }

    constexpr Modint operator *(const Modint &oth) const {
        return Modint(x) *= oth;
    }

    constexpr Modint operator /(const Modint &oth) const {
        return Modint(x) /= oth;
    }

    constexpr Modint operator -() const {
        return Modint((x != 0) * (Mod - x)); 
    }

    template <typename T>
    constexpr typename std::enable_if<std::is_integral<T>::value, const Modint&>::type
    operator =(T t) {
        (*this) = Modint(std::forward<T>(t)); 
        return *this;
    }

    constexpr Modint inv() const {
        return ::math::pow(*this, Mod - 2);
    }

    constexpr ll mod() const {
        return Mod;
    }

private:
    ll x;
};

}

const ll mod = 1e9 + 7;
using mint = math::Modint<mod>;
const std::size_t SIZE = 300 * 300 + 10;

int main() {
    ll n, d, k;
    std::cin >> n >> d >> k;

    tree::BIT<mint> bt(SIZE, mint(0));
    bt.add(0, mint(1));
    for (ll i = 0; i < n; i++) {
        for (ll j = (i + 1) * d; i <= j; j--) {
            ll l = std::max(j - d, i), r = j;
            auto cur = bt.sum(j, j + 1);
            auto nxt = bt.sum(l, r);
            bt.add(j, nxt - cur);
        }
    }

    std::cout << bt.sum(k, k + 1).value() << '\n';
    return 0;
}
0