結果
問題 | No.1043 直列大学 |
ユーザー |
![]() |
提出日時 | 2020-05-01 22:00:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 1,930 bytes |
コンパイル時間 | 2,781 ms |
コンパイル使用メモリ | 194,924 KB |
最終ジャッジ日時 | 2025-01-10 04:48:19 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef LOCAL#include "debug.h"#else#define DEBUG(...)#endiftemplate <class T, class Op = multiplies<T>>constexpr T power(T a, long long n, Op op = Op(), T e = {1}) {assert(n >= 0);while (n) {if (n & 1) e = op(e, a);if (n >>= 1) a = op(a, a);}return e;}template <unsigned M> struct modular {using m = modular;static constexpr unsigned mod = M;unsigned v;modular(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}m operator-() const { return m() -= *this; }m& operator+=(m b) { if ((int)(v += b.v - mod) < 0) v += mod; return *this; }m& operator-=(m b) { if ((int)(v -= b.v) < 0) v += mod; return *this; }m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }m& operator/=(m b) { return *this *= power(b, mod - 2); }friend m operator+(m a, m b) { return a += b; }friend m operator-(m a, m b) { return a -= b; }friend m operator*(m a, m b) { return a *= b; }friend m operator/(m a, m b) { return a /= b; }friend bool operator==(m a, m b) { return a.v == b.v; }};using mint = modular<power(10, 9) + 7>;constexpr int lim = 100 * 1000;int main() {cin.tie(nullptr);ios::sync_with_stdio(false);int n, m;cin >> n >> m;vector<mint> dpv(lim + 2);dpv[0] = 1;for (int _ = n; _--; ) {int v;cin >> v;for (int x = lim - v; x >= 0; --x) {dpv[x + v] += dpv[x];}}vector<mint> dpr(lim + 1);dpr[0] = 1;for (int _ = m; _--; ) {int r;cin >> r;for (int x = lim - r; x >= 0; --x) {dpr[x + r] += dpr[x];}}dpv[0] = 0;for (int x = lim + 1; x--; ) {dpv[x] += dpv[x + 1];}long long a, b;cin >> a >> b;mint res;for (int y = 1; y <= lim; ++y) {auto lb = min<long long>(a * y, lim + 1), ub = min<long long>(y * b + 1, lim + 1);res += dpr[y] * (dpv[lb] - dpv[ub]);}cout << res.v << '\n';}