結果

問題 No.1043 直列大学
ユーザー Plan8Plan8
提出日時 2020-05-09 20:15:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,081 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 205,668 KB
実行使用メモリ 150,596 KB
最終ジャッジ日時 2023-09-20 09:05:41
合計ジャッジ時間 4,124 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 4 ms
5,908 KB
testcase_10 WA -
testcase_11 AC 35 ms
54,196 KB
testcase_12 AC 107 ms
150,596 KB
testcase_13 WA -
testcase_14 AC 42 ms
67,096 KB
testcase_15 AC 50 ms
77,416 KB
testcase_16 AC 43 ms
64,184 KB
testcase_17 AC 24 ms
36,732 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 52 ms
81,312 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 17 ms
24,284 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#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"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#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; }

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;
    }
};

struct combination {
    vector<mint> fact, ifact;
    combination(long long n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(long long n, long long k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(void){
    ll N,M; cin >> N >> M;
    VL V(N), R(M);
    ll sumv = 0, sumr = 0;
    REP(i,N){
        cin >> V[i];
        sumv += V[i];
    }
    REP(i,M){
        cin >> R[i];
        sumr += R[i];
    }
    ll A,B; cin >> A >> B;

    ll sv2[N+1][sumv+1], sr2[M+1][sumr+1];
    REP(i,N+1)REP(j,sumv+1) sv2[i][j] = 0;
    REP(i,M+1)REP(j,sumr+1) sr2[i][j] = 0;

    sv2[0][0] = 1; sr2[0][0] = 1;
    REP(i,N)REP(j,sumv+1){
        (sv2[i+1][j] += sv2[i][j]) %= MOD;
        if(j+V[i] <= sumv) (sv2[i+1][j+V[i]] += sv2[i][j]) %= MOD;
    }
    REP(i,M)REP(j,sumr+1){
        (sr2[i+1][j] += sr2[i][j]) %= MOD;
        if(j+R[i] <= sumr) (sr2[i+1][j+R[i]] += sr2[i][j]) %= MOD;
    }

    VL sv(sumv+1,0), sr(sumr+1,0);
    sv[0] = 1; sr[0] = 1;
    REP(i,sumv) (sv[i+1] += sv[i] + sv2[N][i+1]) %= MOD;
    REP(i,sumr) (sr[i+1] += sr[i] + sr2[N][i+1]) %= MOD;

    mint ans;
    REP(i,sumr){
        ans += sr2[N][i+1]*sv[min(sumv, (i+1)*B)];
    }
    REP(i,sumr){
        ans -= sr2[N][i+1]*sv[min(sumv, (i+1)*A-1)];
    }
    cout << ans.x << endl;
    return 0;
}
0