結果

問題 No.1043 直列大学
ユーザー rxoxixyxdrxoxixyxd
提出日時 2020-05-02 12:25:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,972 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 173,464 KB
実行使用メモリ 814,580 KB
最終ジャッジ日時 2023-08-28 14:26:21
合計ジャッジ時間 5,443 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 61 ms
57,028 KB
testcase_15 RE -
testcase_16 AC 66 ms
61,696 KB
testcase_17 AC 31 ms
30,384 KB
testcase_18 MLE -
testcase_19 RE -
testcase_20 WA -
testcase_21 MLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  vector<int> r(m);
  rep(i, n) cin >> v[i];
  rep(i, m) cin >> r[i];
  ll a, b;
  cin >> a >> b;

  sort(ALL(v));
  sort(ALL(r));

  ll v_sum_max = n * v[n-1] + 1;
  ll r_sum_max = m * r[n-1] + 1;

  // i 番目までの要素を使用して合計が j になる組み合わせ
  vector<vector<int>> dpv(n+1, vector<int>(v_sum_max + v[n-1], 0));
  vector<vector<int>> dpr(m+1, vector<int>(r_sum_max + r[n-1], 0));

  dpv[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v_sum_max; j++) {
        dpv[i][j + v[i-1]] += dpv[i-1][j];
        dpv[i][j] += dpv[i-1][j];
    }
  }

  dpr[0][0] = 1;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < r_sum_max; j++) {
      dpr[i][j + r[i-1]] += dpr[i-1][j];
      dpr[i][j] += dpr[i-1][j];
    }
  }

  vector<int> vs(v_sum_max, 0);  // 合計電圧が i 以下となる組み合わせの数
  for (int i = 1; i < v_sum_max; i++) {
    vs[i] += vs[i-1];
    vs[i] += dpv[n][i];
  }

  mint ans(0);
  for (int i = 1; i < r_sum_max; i++) {
    ll n_res = dpr[m][i];
    // n_vol = a * i <= v <= b * i を満たす v の個数
    if (a*i-1 >= v_sum_max) continue;
    ll n_vol = vs[min(b*i, v_sum_max-1)] - vs[a*i-1];
    ans += n_res * n_vol;
  }

  cout << ans.x << endl;

  return 0;
}
0