結果

問題 No.1043 直列大学
ユーザー TAISA_TAISA_
提出日時 2020-05-01 21:43:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 3,871 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 206,392 KB
実行使用メモリ 6,256 KB
最終ジャッジ日時 2023-08-24 05:40:45
合計ジャッジ時間 4,173 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,944 KB
testcase_01 AC 6 ms
6,008 KB
testcase_02 AC 8 ms
6,256 KB
testcase_03 AC 6 ms
5,968 KB
testcase_04 AC 7 ms
6,124 KB
testcase_05 AC 6 ms
6,184 KB
testcase_06 AC 7 ms
6,160 KB
testcase_07 AC 7 ms
6,012 KB
testcase_08 AC 7 ms
6,156 KB
testcase_09 AC 27 ms
6,116 KB
testcase_10 AC 32 ms
6,096 KB
testcase_11 AC 46 ms
5,952 KB
testcase_12 AC 49 ms
6,084 KB
testcase_13 AC 42 ms
5,968 KB
testcase_14 AC 44 ms
6,120 KB
testcase_15 AC 48 ms
6,012 KB
testcase_16 AC 44 ms
5,964 KB
testcase_17 AC 33 ms
6,096 KB
testcase_18 AC 33 ms
6,076 KB
testcase_19 AC 41 ms
6,012 KB
testcase_20 AC 32 ms
5,960 KB
testcase_21 AC 38 ms
6,084 KB
testcase_22 AC 40 ms
6,084 KB
testcase_23 AC 49 ms
6,164 KB
testcase_24 AC 36 ms
5,996 KB
testcase_25 AC 42 ms
6,012 KB
testcase_26 AC 44 ms
6,044 KB
testcase_27 AC 24 ms
6,116 KB
testcase_28 AC 41 ms
6,120 KB
testcase_29 AC 17 ms
5,964 KB
testcase_30 AC 32 ms
6,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
//from http://noshi91.hatenablog.com/entry/2019/03/31/174006
template <std::uint_fast64_t Modulus>
class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint operator^(const u64 rhs) const noexcept {
        return modint(*this) ^= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    constexpr modint &operator^=(u64 exp) {
        modint rhs = modint(*this);
        a = 1;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    friend ostream &operator<<(ostream &os, const modint &x) {
        os << x.a;
        return os;
    }
    friend istream &operator>>(istream &is, modint &x) {
        is >> x.a;
        return is;
    }
};
using mint = modint<MOD>;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    V<ll> v(n), r(m);
    readv(v);
    readv(r);
    ll a, b;
    cin >> a >> b;
    ll ma = 100010;
    auto calc = [&](V<ll> &a) {
        V<V<mint>> dp(2, V<mint>(ma + 1));
        int pre = 0, cur = 1;
        dp[pre][0] = 1;
        for (int i = 0; i < a.size(); i++) {
            fill(all(dp[cur]), mint(0));
            for (int j = 0; j <= ma; j++) {
                if (j >= a[i]) {
                    dp[cur][j] += dp[pre][j - a[i]];
                }
                dp[cur][j] += dp[pre][j];
            }
            swap(pre, cur);
        }
        return dp[pre];
    };
    V<mint> vs = calc(v), rs = calc(r);
    for (int i = 1; i <= ma; i++) {
        vs[i] += vs[i - 1];
    }
    mint res = 0;
    for (ll i = 1; i <= ma; i++) {
        res += rs[i] * (vs[min(ma, i * b)] - vs[min(ma, max(0LL, i * a - 1))]);
    }
    cout << res << '\n';
}
0