結果
問題 | No.1043 直列大学 |
ユーザー | Haar |
提出日時 | 2020-05-01 22:07:47 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,183 bytes |
コンパイル時間 | 2,275 ms |
コンパイル使用メモリ | 209,752 KB |
実行使用メモリ | 26,832 KB |
最終ジャッジ日時 | 2024-06-07 09:22:46 |
合計ジャッジ時間 | 9,001 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
26,688 KB |
testcase_01 | AC | 22 ms
26,644 KB |
testcase_02 | AC | 32 ms
26,672 KB |
testcase_03 | AC | 22 ms
26,700 KB |
testcase_04 | AC | 23 ms
26,612 KB |
testcase_05 | AC | 23 ms
26,804 KB |
testcase_06 | AC | 22 ms
26,680 KB |
testcase_07 | AC | 27 ms
26,748 KB |
testcase_08 | AC | 27 ms
26,648 KB |
testcase_09 | AC | 135 ms
26,692 KB |
testcase_10 | AC | 156 ms
26,776 KB |
testcase_11 | AC | 225 ms
26,676 KB |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | AC | 160 ms
26,732 KB |
testcase_19 | AC | 217 ms
26,648 KB |
testcase_20 | AC | 158 ms
26,812 KB |
testcase_21 | AC | 191 ms
26,636 KB |
testcase_22 | AC | 205 ms
26,712 KB |
testcase_23 | AC | 253 ms
26,716 KB |
testcase_24 | AC | 177 ms
26,708 KB |
testcase_25 | AC | 210 ms
26,776 KB |
testcase_26 | AC | 222 ms
26,664 KB |
testcase_27 | AC | 114 ms
26,624 KB |
testcase_28 | AC | 208 ms
26,712 KB |
testcase_29 | AC | 76 ms
26,644 KB |
testcase_30 | AC | 167 ms
26,732 KB |
ソースコード
#include <bits/stdc++.h> template <uint32_t M> class ModInt{ public: uint64_t val; constexpr ModInt(): val(0){} constexpr ModInt(std::int64_t n){ if(n >= M) val = n % M; else if(n < 0) val = n % M + M; else val = n; } inline constexpr auto operator+(const ModInt &a) const {return ModInt(val + a.val);} inline constexpr auto operator-(const ModInt &a) const {return ModInt(val - a.val);} inline constexpr auto operator*(const ModInt &a) const {return ModInt(val * a.val);} inline constexpr auto operator/(const ModInt &a) const {return ModInt(val * a.inv().val);} inline constexpr auto& operator=(const ModInt &a){val = a.val; return *this;} inline constexpr auto& operator+=(const ModInt &a){if((val += a.val) >= M) val -= M; return *this;} inline constexpr auto& operator-=(const ModInt &a){if(val < a.val) val += M; val -= a.val; return *this;} inline constexpr auto& operator*=(const ModInt &a){(val *= a.val) %= M; return *this;} inline constexpr auto& operator/=(const ModInt &a){(val *= a.inv().val) %= M; return *this;} inline constexpr bool operator==(const ModInt &a) const {return val == a.val;} inline constexpr bool operator!=(const ModInt &a) const {return val != a.val;} inline constexpr auto& operator++(){*this += 1; return *this;} inline constexpr auto& operator--(){*this -= 1; return *this;} inline constexpr auto operator++(int){auto t = *this; *this += 1; return t;} inline constexpr auto operator--(int){auto t = *this; *this -= 1; return t;} inline constexpr static ModInt power(int64_t n, int64_t p){ if(p < 0) return power(n, -p).inv(); int64_t ret = 1, e = n; for(; p; (e *= e) %= M, p >>= 1) if(p & 1) (ret *= e) %= M; return ret; } inline constexpr static ModInt inv(int64_t a){ int64_t b = M, u = 1, v = 0; while(b){ int64_t t = a / b; a -= t * b; std::swap(a,b); u -= t * v; std::swap(u,v); } u %= M; if(u < 0) u += M; return u; } inline constexpr static auto frac(int64_t a, int64_t b){return ModInt(a) / ModInt(b);} inline constexpr auto power(int64_t p) const {return power(val, p);} inline constexpr auto inv() const {return inv(val);} friend inline constexpr auto operator-(const ModInt &a){return ModInt(-a.val);} friend inline constexpr auto operator+(int64_t a, const ModInt &b){return ModInt(a) + b;} friend inline constexpr auto operator-(int64_t a, const ModInt &b){return ModInt(a) - b;} friend inline constexpr auto operator*(int64_t a, const ModInt &b){return ModInt(a) * b;} friend inline constexpr auto operator/(int64_t a, const ModInt &b){return ModInt(a) / b;} friend std::istream& operator>>(std::istream &s, ModInt<M> &a){s >> a.val; return s;} friend std::ostream& operator<<(std::ostream &s, const ModInt<M> &a){s << a.val; return s;} template <int N> inline static auto div(){ static auto value = inv(N); return value; } }; template <typename T, typename Add = std::plus<T>, typename Minus = std::minus<T>> class CumulativeSum1D{ std::vector<T> data; const int N; const Add add; const Minus minus; bool is_built = false; public: CumulativeSum1D(const std::vector<T> &a, const T &e = 0, const Add &add = Add(), const Minus &minus = Minus()): N(a.size()), add(add), minus(minus) { data.assign(N+1, e); for(int i = 0; i < N; ++i) data[i+1] = a[i]; } CumulativeSum1D(int N, const T &e = 0, const Add &add = Add(), const Minus &minus = Minus()): N(N), add(add), minus(minus) { data.assign(N+1, e); } inline void update(int i, const T &val){ assert(not is_built); data[i+1] = add(data[i+1], val); } inline void build(){ assert(not is_built); for(int i = 0; i < N; ++i) data[i+1] = add(data[i+1], data[i]); is_built = true; } /** * @attention [i, j) */ inline T get(int i, int j) const { assert(is_built); return minus(data[j], data[i]); } }; using mint = ModInt<1000000007>; const int MAX = 100 * 1000 * 5; int main(){ int N, M; std::cin >> N >> M; std::vector<int> V(N), R(M); for(int i = 0; i < N; ++i) std::cin >> V[i]; for(int i = 0; i < M; ++i) std::cin >> R[i]; int A, B; std::cin >> A >> B; mint ans = 0; std::vector<std::vector<mint>> dpv(2, std::vector<mint>(MAX + 1)); dpv[0][0] = 1; for(int i = 0; i < N; ++i){ int cur = i % 2, nxt = (i + 1) % 2; for(int j = 0; j <= MAX; ++j){ if(j >= V[i]) dpv[nxt][j] = dpv[cur][j-V[i]] + dpv[cur][j]; else dpv[nxt][j] = dpv[cur][j]; } } CumulativeSum1D<mint> c(dpv[N%2]); c.build(); std::vector<std::vector<mint>> dpr(2, std::vector<mint>(MAX + 1)); dpr[0][0] = 1; for(int i = 0; i < M; ++i){ int cur = i % 2, nxt = (i + 1) % 2; for(int j = 0; j <= MAX; ++j){ if(j >= R[i]) dpr[nxt][j] = dpr[cur][j-R[i]] + dpr[cur][j]; else dpr[nxt][j] = dpr[cur][j]; } } for(int r = 1; r <= MAX; ++r){ int64_t lb = r * A; if(lb > MAX) continue; int64_t ub = r * B; if(ub > MAX) ub = MAX; ans += dpr[M%2][r] * c.get(lb, ub+1); } std::cout << ans << std::endl; return 0; }