結果
問題 | No.1043 直列大学 |
ユーザー | Haar |
提出日時 | 2020-05-01 22:05:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,177 bytes |
コンパイル時間 | 2,319 ms |
コンパイル使用メモリ | 210,196 KB |
実行使用メモリ | 8,048 KB |
最終ジャッジ日時 | 2024-06-07 09:04:35 |
合計ジャッジ時間 | 5,283 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
7,912 KB |
testcase_01 | AC | 8 ms
8,040 KB |
testcase_02 | AC | 9 ms
7,912 KB |
testcase_03 | AC | 7 ms
7,908 KB |
testcase_04 | AC | 7 ms
7,916 KB |
testcase_05 | AC | 7 ms
8,044 KB |
testcase_06 | AC | 7 ms
7,908 KB |
testcase_07 | AC | 8 ms
7,912 KB |
testcase_08 | AC | 9 ms
8,044 KB |
testcase_09 | AC | 30 ms
7,920 KB |
testcase_10 | AC | 35 ms
7,912 KB |
testcase_11 | AC | 50 ms
8,044 KB |
testcase_12 | RE | - |
testcase_13 | AC | 54 ms
7,916 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | AC | 38 ms
7,912 KB |
testcase_19 | AC | 52 ms
7,912 KB |
testcase_20 | AC | 36 ms
7,916 KB |
testcase_21 | AC | 48 ms
7,912 KB |
testcase_22 | AC | 50 ms
7,916 KB |
testcase_23 | AC | 69 ms
7,920 KB |
testcase_24 | AC | 42 ms
7,916 KB |
testcase_25 | AC | 52 ms
8,044 KB |
testcase_26 | AC | 57 ms
7,916 KB |
testcase_27 | AC | 26 ms
7,916 KB |
testcase_28 | AC | 47 ms
7,916 KB |
testcase_29 | AC | 18 ms
7,912 KB |
testcase_30 | AC | 43 ms
7,916 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 + 100; 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){ int lb = r * A; if(lb > MAX) continue; int 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; }