結果

問題 No.1043 直列大学
ユーザー risujirohrisujiroh
提出日時 2020-05-01 22:00:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,930 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 200,548 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 05:42:31
合計ジャッジ時間 3,434 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,384 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 10 ms
4,384 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 17 ms
4,380 KB
testcase_12 AC 18 ms
4,380 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 16 ms
4,380 KB
testcase_17 AC 13 ms
4,380 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 15 ms
4,376 KB
testcase_20 AC 12 ms
4,380 KB
testcase_21 AC 15 ms
4,376 KB
testcase_22 AC 15 ms
4,380 KB
testcase_23 AC 18 ms
4,380 KB
testcase_24 AC 13 ms
4,380 KB
testcase_25 AC 15 ms
4,376 KB
testcase_26 AC 17 ms
4,376 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 15 ms
4,376 KB
testcase_29 AC 6 ms
4,376 KB
testcase_30 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <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';
}
0