結果

問題 No.1043 直列大学
ユーザー optopt
提出日時 2020-05-01 23:25:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 3,516 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 204,308 KB
実行使用メモリ 5,412 KB
最終ジャッジ日時 2023-08-24 12:34:31
合計ジャッジ時間 3,749 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 9 ms
4,428 KB
testcase_10 AC 12 ms
4,688 KB
testcase_11 AC 24 ms
5,304 KB
testcase_12 AC 29 ms
5,412 KB
testcase_13 AC 24 ms
4,996 KB
testcase_14 AC 22 ms
5,088 KB
testcase_15 AC 28 ms
5,360 KB
testcase_16 AC 22 ms
5,088 KB
testcase_17 AC 13 ms
4,628 KB
testcase_18 AC 15 ms
4,424 KB
testcase_19 AC 23 ms
4,948 KB
testcase_20 AC 12 ms
4,736 KB
testcase_21 AC 21 ms
4,676 KB
testcase_22 AC 21 ms
4,940 KB
testcase_23 AC 29 ms
5,352 KB
testcase_24 AC 16 ms
4,676 KB
testcase_25 AC 22 ms
4,892 KB
testcase_26 AC 25 ms
5,200 KB
testcase_27 AC 7 ms
4,376 KB
testcase_28 AC 19 ms
4,820 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 18 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


struct mint {
  ll x;
  mint(ll xx=0) : x(xx) { if (xx >= MOD || xx <= -MOD) x = xx % MOD; if (x < 0) x += MOD; }
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
  mint& operator-=(const mint a) { if ((x -= a.x) < 0) x += MOD; return *this; }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint& operator/=(const mint r) {
    ll a = r.x, b = MOD, u = 1, v = 0;
    while (b) {
      ll t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    x = x * u % MOD;
    if (x < 0) x += MOD;
    return *this;
  }
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
// istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
using Vm = vector<mint>;


int main() {
  ll n, m; cin >> n >> m;
  V v(n), r(m); cin >> v >> r;
  ll a, b; cin >> a >> b;

  int N = n * 1000;
  int M = m * 1000;
  Vm dpv(N+1), dpr(M+1);
  dpv[0] = 1;
  dpr[0] = 1;

  rep(i, n) drep(j, N) if (j >= v[i]) dpv[j] += dpv[j-v[i]];
  rep(i, m) drep(j, M) if (j >= r[i]) dpr[j] += dpr[j-r[i]];

  Vm s(M+1);
  drep(i, M) s[i] = s[i+1] + dpr[i];

  mint ans = -1;
  rep(i, N+1) {
    int j = (i+b-1)/b;
    if (j <= M) ans += dpv[i] * s[j];
    j = i/a + 1;
    if (j <= M) ans -= dpv[i] * s[j];
  }
  
  cout << ans << "\n";
  return 0;
}
0