結果

問題 No.1011 Infinite Stairs
ユーザー Plan8Plan8
提出日時 2020-03-20 22:13:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 5,552 bytes
コンパイル時間 2,570 ms
コンパイル使用メモリ 192,492 KB
実行使用メモリ 597,612 KB
最終ジャッジ日時 2024-05-08 22:20:15
合計ジャッジ時間 6,298 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 166 ms
19,712 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template <typename T,typename E>
struct LazySegmentTree{
    typedef function<T(T,T)> F;
    typedef function<T(T,E)> G;
    typedef function<E(E,E)> H;
    typedef function<E(E,int)> P;
    int n;
    F f;
    G g;
    H h;
    P p;
    T d1;
    E d0;
    vector<T> val;
    vector<E> lazy;

    LazySegmentTree(vector<T> a, F f_, G g_, H h_, T d1_, E d0_, P p_=[](E a,int b){return a;}):
        f(f_),g(g_),h(h_),d1(d1_),d0(d0_),p(p_){

        int sz = a.size();
        n = 1;
        while (n < sz) n <<= 1;
        val.clear();
        val.resize(2 * n - 1, d1);
        lazy.clear();
        lazy.resize(2 * n - 1, d0);
        for (int i = 0; i < sz; i++) val[i + n - 1] = a[i];
        for (int i = n - 2; i >= 0; i--) val[i] = f(val[i * 2 + 1], val[i * 2 + 2]);
    }

    LazySegmentTree() {};
    void init(vector<T> a, F f_, G g_, H h_, T d1_, E d0_, P p_=[](E a,int b){return a;}){
        f=f_; g=g_; h=h_; d1=d1_; d0=d0_; p=p_;
        int sz = a.size();
        n = 1;
        while (n < sz) n <<= 1;
        val.clear();
        val.resize(2 * n - 1, d1);
        lazy.clear();
        lazy.resize(2 * n - 1, d0);
        for (int i = 0; i < sz; i++) val[i + n - 1] = a[i];
        for (int i = n - 2; i >= 0; i--) val[i] = f(val[i * 2 + 1], val[i * 2 + 2]);
    }

    inline void eval(int k, int len){
        if(lazy[k] == d0) return;

        if(2*k+1 < 2*n-1){
            lazy[2*k+1] = h(lazy[2*k+1], lazy[k]);
            lazy[2*k+2] = h(lazy[2*k+2], lazy[k]);
        }
        val[k] = g(val[k], p(lazy[k], len));
        lazy[k] = d0;
    }

    void update(int a, int b, E x, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        eval(k, r-l);
        if(r <=a || b <= l) return;

        if(a <= l && r <= b){
            lazy[k] = h(lazy[k], x);
            eval(k, r-l);
        }
        else{
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            val[k] = f(val[2*k+1], val[2*k+2]);
        }
    }

    T query(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        eval(k, r-l);
        if(r <= a || b <= l) return d1;
        if(a <= l && r <= b) return val[k];
        T val_l = query(a, b , 2*k+1, l, (l+r)/2);
        T val_r = query(a, b , 2*k+2, (l+r)/2, r);
        return f(val_l, val_r);
    }

    T get(int pos){
        int k = pos + n - 1;
        eval(k, 1);
        return val[k];
    }
};

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
    	return *this;
    }
    mint& operator*=(const mint a) {
    	(x *= a.x) %= MOD;
    	return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
    	return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(void){
    auto f = [](mint a, mint b){return a+b;};
    auto g = [](mint a, ll b){return a+b;};
    auto h = [](ll a, ll b){return a+b;};
    auto p = [](ll a, int b){return a*(ll)b;};
    ll N,d,K; cin >> N >> d >> K;
    vector<mint> a(K+1); REP(i,K+1) a[i] = 0;
    LazySegmentTree<mint, ll> st[N+1];
    REP(i,N+1) st[i].init(a,f,g,h,mint(0),0,p);
    st[0].update(0,1,1);
    REP(i,N)REP(j,K){
        mint t = st[i].query(j,j+1);
        if(t.x > 0){
            st[i+1].update(j+1,min(K,j+d)+1,t.x);
        }
    }
    ll ans = st[N].query(K,K+1).x;
    cout << ans << en;
    return 0;
}
0