結果

問題 No.1043 直列大学
ユーザー betit0919betit0919
提出日時 2020-05-01 23:57:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,833 bytes
コンパイル時間 1,021 ms
コンパイル使用メモリ 112,204 KB
実行使用メモリ 8,620 KB
最終ジャッジ日時 2023-08-24 12:36:35
合計ジャッジ時間 3,192 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
8,532 KB
testcase_01 AC 8 ms
8,484 KB
testcase_02 AC 9 ms
8,416 KB
testcase_03 AC 7 ms
8,568 KB
testcase_04 AC 7 ms
8,524 KB
testcase_05 AC 8 ms
8,620 KB
testcase_06 AC 7 ms
8,400 KB
testcase_07 AC 9 ms
8,364 KB
testcase_08 AC 9 ms
8,352 KB
testcase_09 AC 33 ms
8,396 KB
testcase_10 AC 38 ms
8,452 KB
testcase_11 AC 55 ms
8,384 KB
testcase_12 AC 59 ms
8,408 KB
testcase_13 AC 51 ms
8,492 KB
testcase_14 AC 53 ms
8,376 KB
testcase_15 AC 57 ms
8,484 KB
testcase_16 AC 52 ms
8,504 KB
testcase_17 AC 40 ms
8,372 KB
testcase_18 AC 40 ms
8,540 KB
testcase_19 AC 49 ms
8,536 KB
testcase_20 AC 39 ms
8,372 KB
testcase_21 AC 46 ms
8,540 KB
testcase_22 AC 48 ms
8,404 KB
testcase_23 AC 59 ms
8,380 KB
testcase_24 AC 43 ms
8,484 KB
testcase_25 AC 50 ms
8,420 KB
testcase_26 AC 52 ms
8,376 KB
testcase_27 AC 30 ms
8,392 KB
testcase_28 AC 49 ms
8,416 KB
testcase_29 AC 20 ms
8,396 KB
testcase_30 AC 39 ms
8,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N,M,A,B;
  cin>>N>>M;
  vector<ll>V(N),R(M);
  vector<vector<ll>> dp1(2,vector<ll>(100001)),dp2(2,vector<ll>(100001));
  REP(i,N)cin>>V[i];
  REP(i,M)cin>>R[i];
  cin>>A>>B;
  dp1[0][0]=1;dp2[0][0]=1;

  REP(i,N){
    // V[i]を使うかどうか
    REP(j,100001){
      if(j-V[i]>=0){
        dp1[(i+1)%2][j] = dp1[i%2][j-V[i]] + dp1[i%2][j];
      }else{
        dp1[(i+1)%2][j] = dp1[i%2][j];
      }
      dp1[(i+1)%2][j]%=MOD;
    }
  }
  REP(i,M){
    // R[i]を使うかどうか
    REP(j,100001){
      if(j-R[i]>=0){
        dp2[(i+1)%2][j] = dp2[i%2][j-R[i]] + dp2[i%2][j];
      }else{
        dp2[(i+1)%2][j] = dp2[i%2][j];
      }
      dp2[(i+1)%2][j]%=MOD;
    }
  }
  vector<ll>v=dp1[N%2],r=dp2[M%2];
  vector<ll>Vsum(100002);
  REP(i,100001){
    Vsum[i+1]=Vsum[i]+v[i];
    Vsum[i+1]%=MOD;
  }
  ll ans=0;
  REP(i,100001){
    ans+=r[i]*(Vsum[min(100000ll,i*B+1)]-Vsum[min(100000ll,i*A)]);
    ans%=MOD;
  }
  cout<<(ans-1+MOD)%MOD<<endl;
}
0