結果

問題 No.1474 かさまJ
ユーザー むかでむかで
提出日時 2021-04-10 00:12:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 2,500 ms
コード長 4,359 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 204,116 KB
実行使用メモリ 272,724 KB
最終ジャッジ日時 2023-09-07 19:12:12
合計ジャッジ時間 5,061 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
272,468 KB
testcase_01 AC 67 ms
272,544 KB
testcase_02 AC 68 ms
272,484 KB
testcase_03 AC 68 ms
272,500 KB
testcase_04 AC 67 ms
272,540 KB
testcase_05 AC 119 ms
272,448 KB
testcase_06 AC 77 ms
272,472 KB
testcase_07 AC 69 ms
272,472 KB
testcase_08 AC 68 ms
272,528 KB
testcase_09 AC 140 ms
272,424 KB
testcase_10 AC 69 ms
272,468 KB
testcase_11 AC 67 ms
272,476 KB
testcase_12 AC 67 ms
272,724 KB
testcase_13 AC 145 ms
272,560 KB
testcase_14 AC 90 ms
272,536 KB
testcase_15 AC 77 ms
272,552 KB
testcase_16 AC 69 ms
272,504 KB
testcase_17 AC 93 ms
272,484 KB
testcase_18 AC 170 ms
272,672 KB
testcase_19 AC 185 ms
272,468 KB
testcase_20 AC 193 ms
272,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

//-------------------------------------------------
//--ModInt
//-------------------------------------------------
constexpr uint_fast64_t MOD = 1e9+7;

class mint
{
private:
    using Value = uint_fast64_t;
    Value n;
public:
    mint():n(0){}
    mint(int_fast64_t _n):n(_n<0 ? MOD-(-_n)%MOD : _n%MOD){}
    mint(const mint &m):n(m.n){}

    friend ostream& operator<<(ostream &os, const mint &a){
		return os << a.n;
	}
    friend istream& operator>>(istream &is, mint &a){
        Value temp; is>>temp;
        a = mint(temp);
        return is;
    }

    mint& operator+=(const mint &m){n+=m.n; n=(n<MOD)?n:n-MOD; return *this;}
    mint& operator-=(const mint &m){n+=MOD-m.n; n=(n<MOD)?n:n-MOD; return *this;}
    mint& operator*=(const mint &m){n=n*m.n%MOD; return *this;}
    mint& operator/=(const mint &m){return *this*=m.inv();}
    mint& operator++(){return *this+=1;}
    mint& operator--(){return *this-=1;}

    mint operator+(const mint &m) const {return mint(*this)+=m;}
    mint operator-(const mint &m) const {return mint(*this)-=m;}
    mint operator*(const mint &m) const {return mint(*this)*=m;}
    mint operator/(const mint &m) const {return mint(*this)/=m;}
    mint operator++(int){mint t(*this); *this+=1; return t;}
    mint operator--(int){mint t(*this); *this-=1; return t;}

    bool operator==(const mint &m) const {return n==m.n;}
    bool operator!=(const mint &m) const {return n!=m.n;}
    mint operator-() const {return mint(MOD-n);}

    mint pow(Value b) const {
        mint ret(1), m(*this);
        while(b){
            if (b & 1) ret*=m;
            m*=m;
            b>>=1;
        }
        return ret;
    }

    mint inv() const {return pow(MOD-2);}
};

//-------------------------------------------------
//--Combination (depends on ModInt)
//-------------------------------------------------
class Combination
{
private:
    ::std::vector<mint> _fact;
    ::std::vector<mint> _finv;
public:
    Combination(int n):_fact(n+1), _finv(n+1){
        _fact[0] = _fact[1] = 1;
        _finv[0] = _finv[1] = 1;
        for(int i=2; i<=n; i++){
            _fact[i] = _fact[i-1]*i;
            _finv[i] = _fact[i].inv();
        }
    }
    mint fact(int x){return _fact[x];}
    mint finv(int x){return _finv[x];}
    mint comb(int x, int y){
        if (y>x || y<0) return 0;
        return _fact[x]*_finv[y]*_finv[x-y];
    }
    mint homo(int x, int y){return comb(x+y-1, y);}
};

//-------------------------------------------------

constexpr int N_MAX = 40;
constexpr int M_MAX = 20000;

mint dp[N_MAX+1][M_MAX+1];
mint sum[N_MAX+1][N_MAX+1][M_MAX+2];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N,Mp,Mq,L; cin>>N>>Mp>>Mq>>L;
	Combination bn(M_MAX+N_MAX);
	vi S(N);
	rep(i,N) cin>>S[i];
	
	dp[0][0]=1;

	rep(i,N)FOR(j,0,N){
		FOR(k,0,Mq){
			sum[i][j][k+1] = sum[i][j][k]+dp[j][k];
		}
		FOR(k,0,Mq){
			if (j>0){
				dp[j][k] += sum[i][j-1][k]-sum[i][j-1][max(0,k-S[i])];
			}
		}
	}
	mint ans=0;
	FOR(j,0,N)FOR(k,0,Mq){
		int p = Mp-(L*j-k);
		if (p<0 || p>Mp) continue;
		ans += bn.comb(p+N-1,N-1)*dp[j][k];
	}
	cout<<ans<<"\n";
    return 0;
}
0