結果

問題 No.1043 直列大学
ユーザー saxofone111saxofone111
提出日時 2020-05-04 12:03:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 2,361 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 165,044 KB
実行使用メモリ 161,652 KB
最終ジャッジ日時 2023-08-24 12:46:13
合計ジャッジ時間 10,186 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
161,328 KB
testcase_01 AC 45 ms
161,400 KB
testcase_02 AC 55 ms
161,344 KB
testcase_03 AC 45 ms
161,408 KB
testcase_04 AC 45 ms
161,344 KB
testcase_05 AC 46 ms
161,476 KB
testcase_06 AC 45 ms
161,336 KB
testcase_07 AC 49 ms
161,540 KB
testcase_08 AC 49 ms
161,412 KB
testcase_09 AC 228 ms
161,340 KB
testcase_10 AC 297 ms
161,412 KB
testcase_11 AC 431 ms
161,328 KB
testcase_12 AC 465 ms
161,408 KB
testcase_13 AC 358 ms
161,340 KB
testcase_14 AC 352 ms
161,376 KB
testcase_15 AC 342 ms
161,328 KB
testcase_16 AC 291 ms
161,336 KB
testcase_17 AC 220 ms
161,336 KB
testcase_18 AC 281 ms
161,316 KB
testcase_19 AC 355 ms
161,444 KB
testcase_20 AC 268 ms
161,340 KB
testcase_21 AC 330 ms
161,320 KB
testcase_22 AC 339 ms
161,328 KB
testcase_23 AC 437 ms
161,376 KB
testcase_24 AC 304 ms
161,320 KB
testcase_25 AC 355 ms
161,652 KB
testcase_26 AC 380 ms
161,472 KB
testcase_27 AC 202 ms
161,412 KB
testcase_28 AC 365 ms
161,332 KB
testcase_29 AC 129 ms
161,336 KB
testcase_30 AC 277 ms
161,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll N, M;
ll dpV[101][100100];
ll dpR[101][100100];
ll V[110], R[110];
ll A, B;

ll dpfV(ll n, ll v){
  if(v>=100100){
    return dpfV(n, 100099);
  }else if(dpV[n][v]>=0){
    return dpV[n][v];
  }else{
    dpV[n][v]=0;
    if(n==0)dpV[n][v]=1;
    else{
      dpV[n][v]=dpfV(n-1, v)%MOD;
      if(v-V[n-1]>=0){
        dpV[n][v] =mod(dpV[n][v]+dpfV(n-1, v-V[n-1]), MOD);
      }
    }
    return dpV[n][v];
  }
}

ll dpfR(ll n, ll v){
  if(v>=100100){
    return dpfR(n, 100099);
  }else if(dpR[n][v]>=0){
    return dpR[n][v];
  }else{
    dpR[n][v]=0;
    if(n==0){
      if(v==0)dpR[n][v]=1;
    }
    else{
      dpR[n][v]=dpfR(n-1, v)%MOD;
      if(v-R[n-1]>=0){
        dpR[n][v] =mod(dpR[n][v]+dpfR(n-1, v-R[n-1]), MOD);
      }
    }
    return dpR[n][v];
  }
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> M;
  rep(i, N)cin >> V[i];
  rep(i, M)cin >> R[i];
  cin >> A >> B;
  fill(dpV[0], dpV[101], -100);
  fill(dpR[0], dpR[101], -100);
  ll ans = 0;
  rep(i, 100000){
    ll vnum = mod(dpfV(N, (i+1)*B) - dpfV(N, (i+1)*A - 1),MOD);
    //cout << vnum << endl;
    ans = mod(ans+dpfR(M, i+1)*vnum,MOD);
  }
  cout << ans;
  return 0;
}
0