結果

問題 No.1043 直列大学
ユーザー rogi52rogi52
提出日時 2022-08-17 13:31:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,500 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 199,076 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 03:57:44
合計ジャッジ時間 3,851 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 4 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 16 ms
6,940 KB
testcase_10 AC 18 ms
6,944 KB
testcase_11 AC 26 ms
6,944 KB
testcase_12 AC 28 ms
6,944 KB
testcase_13 AC 24 ms
6,940 KB
testcase_14 AC 25 ms
6,944 KB
testcase_15 AC 27 ms
6,944 KB
testcase_16 AC 25 ms
6,944 KB
testcase_17 AC 19 ms
6,940 KB
testcase_18 AC 18 ms
6,940 KB
testcase_19 AC 24 ms
6,940 KB
testcase_20 AC 19 ms
6,940 KB
testcase_21 AC 21 ms
6,940 KB
testcase_22 AC 22 ms
6,944 KB
testcase_23 AC 27 ms
6,940 KB
testcase_24 AC 21 ms
6,940 KB
testcase_25 AC 23 ms
6,944 KB
testcase_26 AC 25 ms
6,944 KB
testcase_27 AC 14 ms
6,948 KB
testcase_28 AC 24 ms
6,944 KB
testcase_29 AC 10 ms
6,944 KB
testcase_30 AC 19 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

template< int mod >
struct Fp {
    int x;
    Fp() : x(0) {}
    Fp(int64_t y) : x(y >= 0 ? y % mod : (mod + y % mod) % mod) {}
    Fp &operator+=(const Fp &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    Fp &operator-=(const Fp &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
    Fp &operator*=(const Fp &p) { x = (int)(1LL * x * p.x % mod); return *this; }
    Fp &operator/=(const Fp &p) { *this *= p.inv(); return *this; }
    Fp operator-() const { return Fp(-x); }
    Fp operator+(const Fp &p) const { return Fp(*this) += p; }
    Fp operator-(const Fp &p) const { return Fp(*this) -= p; }
    Fp operator*(const Fp &p) const { return Fp(*this) *= p; }
    Fp operator/(const Fp &p) const { return Fp(*this) /= p; }
    bool operator==(const Fp &p) const { return x == p.x; }
    bool operator!=(const Fp &p) const { return x != p.x; }

    Fp inv() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return Fp(u);
    }

    Fp pow(int64_t n) const {
        Fp ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const Fp &p) { return os << p.x; }
    friend istream &operator>>(istream &is, Fp &a) {
        int64_t t;
        is >> t;
        a = Fp< mod > (t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = Fp<1000000007>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,M; cin >> N >> M;
    vector<int> V(N), R(M);
    rep(i,N) cin >> V[i];
    rep(i,M) cin >> R[i];
    ll A,B; cin >> A >> B;

    const ll SIZE = 101010;
    vector<mint> dp_v(SIZE, 0), dp_r(SIZE, 0);
    dp_v[0] = 1;
    rep(i,N) {
        for(int s = SIZE - 1 - V[i]; s >= 0; s--) {
            dp_v[s + V[i]] += dp_v[s];
        }
    }
    dp_r[0] = 1;
    rep(i,M) {
        for(int s = SIZE - 1 - R[i]; s >= 0; s--) {
            dp_r[s + R[i]] += dp_r[s];
        }
    }
    vector<mint> v_sum(SIZE + 1, 0);
    rep(i,SIZE) v_sum[i + 1] += v_sum[i] + dp_v[i];

    mint ans = 0;
    for(ll r = 1; r < SIZE; r++) {
        ans += (v_sum[min(B * r + 1, SIZE)] - v_sum[min(A * r, SIZE)]) * dp_r[r];
    }
    cout << ans << endl;
}
0