結果

問題 No.1043 直列大学
ユーザー どららどらら
提出日時 2020-05-01 22:16:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,892 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 173,796 KB
実行使用メモリ 89,748 KB
最終ジャッジ日時 2023-08-26 14:35:20
合計ジャッジ時間 5,336 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
89,360 KB
testcase_01 AC 66 ms
89,484 KB
testcase_02 AC 66 ms
89,480 KB
testcase_03 AC 65 ms
89,360 KB
testcase_04 AC 65 ms
89,480 KB
testcase_05 AC 65 ms
89,564 KB
testcase_06 AC 65 ms
89,408 KB
testcase_07 AC 65 ms
89,564 KB
testcase_08 AC 66 ms
89,356 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 93 ms
89,356 KB
testcase_15 AC 98 ms
89,532 KB
testcase_16 AC 91 ms
89,360 KB
testcase_17 AC 81 ms
89,536 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 75 ms
89,408 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(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 ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 200005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};
modutils mutil;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> v, w;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  rep(i,M){
    int a;
    cin >> a;
    w.push_back(a);
  }
  int A, B;
  cin >> A >> B;

  vector<vector<int>> dpV(105, vector<int>(100005, 0));
  dpV[0][0] = 1;
  rep(i,v.size()){
    rep(j,100005){
      if(dpV[i][j] > 0){
        dpV[i+1][j] += dpV[i][j];
        dpV[i+1][j + v[i]] += dpV[i][j];
      }
    }
  }
  vector<vector<int>> dpR(105, vector<int>(100005, 0));
  dpR[0][0] = 1;
  rep(i,w.size()){
    rep(j,100005){
      if(dpR[i][j] > 0){
        dpR[i+1][j] += dpR[i][j];
        dpR[i+1][j + w[i]] += dpR[i][j];
      }
    }
  }

  vector<mint> sumR(100005, 0);
  REP(i,1,100005) sumR[i] = sumR[i-1] + dpR[N][i];

  mint ret(0);
  REP(i,1,100005){
    mint cnt = dpV[N][i];
    int lhs = (i+B-1) / B - 1;
    int rhs = i / A;
    ret += cnt * (sumR[rhs] - sumR[lhs]);
  }

  cout << ret << endl;

  return 0;
}

0