結果

問題 No.1043 直列大学
ユーザー tsutajtsutaj
提出日時 2020-05-01 22:01:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 4,292 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 103,804 KB
実行使用メモリ 19,240 KB
最終ジャッジ日時 2023-08-24 05:43:01
合計ジャッジ時間 8,503 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
19,056 KB
testcase_01 AC 14 ms
19,072 KB
testcase_02 AC 27 ms
19,232 KB
testcase_03 AC 14 ms
18,976 KB
testcase_04 AC 14 ms
19,100 KB
testcase_05 AC 14 ms
19,164 KB
testcase_06 AC 13 ms
18,964 KB
testcase_07 AC 21 ms
19,124 KB
testcase_08 AC 20 ms
19,040 KB
testcase_09 AC 176 ms
19,240 KB
testcase_10 AC 209 ms
18,992 KB
testcase_11 AC 347 ms
19,104 KB
testcase_12 AC 338 ms
19,108 KB
testcase_13 AC 311 ms
18,964 KB
testcase_14 AC 302 ms
19,036 KB
testcase_15 AC 332 ms
18,936 KB
testcase_16 AC 291 ms
19,108 KB
testcase_17 AC 213 ms
18,972 KB
testcase_18 AC 222 ms
19,044 KB
testcase_19 AC 328 ms
19,016 KB
testcase_20 AC 244 ms
19,040 KB
testcase_21 AC 362 ms
19,072 KB
testcase_22 AC 381 ms
19,048 KB
testcase_23 AC 459 ms
19,072 KB
testcase_24 AC 285 ms
18,976 KB
testcase_25 AC 368 ms
18,944 KB
testcase_26 AC 423 ms
18,936 KB
testcase_27 AC 157 ms
19,108 KB
testcase_28 AC 272 ms
19,036 KB
testcase_29 AC 92 ms
18,996 KB
testcase_30 AC 202 ms
18,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

// ModInt begin

using ll = long long;
template<ll mod>
struct ModInt {
    ll v;
    ll mod_pow(ll x, ll n) const {
        return (!n) ? 1 : (mod_pow((x*x)%mod,n/2) * ((n&1)?x:1)) % mod;
    }
    ModInt(ll a = 0) : v((a %= mod) < 0 ? a + mod : a) {}
    ModInt operator+ ( const ModInt& b ) const {
        return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
    }
    ModInt operator- () const {
        return ModInt(-v);
    }
    ModInt operator- ( const ModInt& b ) const {
        return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
    }
    ModInt operator* ( const ModInt& b ) const {return (v * b.v) % mod;}
    ModInt operator/ ( const ModInt& b ) const {return (v * mod_pow(b.v, mod-2)) % mod;}
    
    bool operator== ( const ModInt &b ) const {return v == b.v;}
    bool operator!= ( const ModInt &b ) const {return !(*this == b); }
    ModInt& operator+= ( const ModInt &b ) {
        v += b.v;
        if(v >= mod) v -= mod;
        return *this;
    }
    ModInt& operator-= ( const ModInt &b ) {
        v -= b.v;
        if(v < 0) v += mod;
        return *this;
    }
    ModInt& operator*= ( const ModInt &b ) {
        (v *= b.v) %= mod;
        return *this;
    }
    ModInt& operator/= ( const ModInt &b ) {
        (v *= mod_pow(b.v, mod-2)) %= mod;
        return *this;
    }
    ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
    // operator int() const { return int(v); }
    // operator long long int() const { return v; }
};

template<ll mod>
ModInt<mod> pow(ModInt<mod> n, ll k) {
    return ModInt<mod>(n.mod_pow(n.v, k));
}

template<ll mod>
ostream& operator<< (ostream& out, ModInt<mod> a) {return out << a.v;}
template<ll mod>
istream& operator>> (istream& in, ModInt<mod>& a) {
    in >> a.v;
    return in;
}

// ModInt end
using mint = ModInt<MOD>;

mint dp1[1000010], dp2[1000010];
int main() {
    int N, M; scanf("%d%d", &N, &M);
    vector<int> V(N), R(M);
    for(int i=0; i<N; i++) scanf("%d", &V[i]);
    for(int i=0; i<M; i++) scanf("%d", &R[i]);
    int A, B; scanf("%d%d", &A, &B);

    mint ans(-1);
    const int MAXP = 1000005;
    {
        dp1[0] = mint(1);
        for(int i=0; i<M; i++) {
            for(int j=MAXP; j>=0; j--) {
                if(dp1[j] == mint(0)) continue;
                int nj = min(MAXP, j + B*R[i]);
                dp1[nj] += dp1[j];
            }
        }

        for(int i=0; i<N; i++) {
            for(int j=0; j<=MAXP; j++) {
                if(dp1[j] == mint(0)) continue;
                int nj = j - V[i];
                if(nj >= 0) dp1[nj] += dp1[j];
            }
        }

        for(int i=0; i<=MAXP; i++) {
            if(dp1[i] == mint(0)) continue;
            ans += dp1[i];
        }
    }

    {
        dp2[0] = mint(1);
        for(int i=0; i<M; i++) {
            for(int j=MAXP; j>=0; j--) {
                if(dp2[j] == mint(0)) continue;
                int nj = min(MAXP, j + A*R[i]);
                dp2[nj] += dp2[j];
            }
        }

        for(int i=0; i<N; i++) {
            for(int j=0; j<=MAXP; j++) {
                if(dp2[j] == mint(0)) continue;
                int nj = j - V[i];
                if(nj >= 0) dp2[nj] += dp2[j];
            }
        }

        for(int i=1; i<=MAXP; i++) {
            if(dp2[i] == mint(0)) continue;
            ans -= dp2[i];
        }
    }
    cout << ans << endl;
    return 0;
}
0