結果

問題 No.1043 直列大学
ユーザー monkukui2monkukui2
提出日時 2020-05-01 21:44:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,354 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 101,960 KB
実行使用メモリ 83,556 KB
最終ジャッジ日時 2023-08-26 08:50:51
合計ジャッジ時間 8,899 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 8 ms
6,144 KB
testcase_02 AC 13 ms
9,196 KB
testcase_03 AC 9 ms
6,148 KB
testcase_04 AC 9 ms
6,024 KB
testcase_05 AC 9 ms
6,140 KB
testcase_06 AC 10 ms
6,128 KB
testcase_07 AC 12 ms
7,636 KB
testcase_08 AC 12 ms
7,728 KB
testcase_09 AC 75 ms
44,420 KB
testcase_10 AC 88 ms
57,892 KB
testcase_11 RE -
testcase_12 AC 239 ms
83,556 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

vector<lint> culc(vector<lint> a) {
  int n = a.size();
  lint m = 100 * 1000;
  vector<vector<lint>> dp(n + 1, vector<lint> (m + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      if (dp[i][j] == 0) continue;

      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= MOD;

      dp[i + 1][j + a[i]] += dp[i][j];
      dp[i + 1][j + a[i]] %= MOD;
    }
  }
  return dp[n];
}

// 抽象累積和
// 構築 O(n), get O(1)

template<typename T>
struct CumSum{
private: 
  size_t n;
  vector<T> dat;

public: 
  CumSum(const vector<T> &v){
    n = v.size();
    dat.resize(n + 1, 0);
    for(size_t i = 0; i < n; i++){
      dat[i + 1] = dat[i] + v[i];
      dat[i + 1] %= MOD;
    }
  }

  T get(size_t r) const { // 0-indexed, [0. r)
    return dat[r];
  }

  T get(size_t l, size_t r){ // 0-indexed, [l, r)
    return (dat[r] - dat[l] + MOD) % MOD;
  }
};

int main() {
  
  int n, m; cin >> n >> m;
  vector<lint> v(n);
  vector<lint> r(m);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> r[i];
  }

  lint a, b; cin >> a >> b;

  auto dp1 = culc(v);
  auto dp2 = culc(r);

  // 抵抗を決め打ち

  CumSum<lint> acc(dp1);


  lint ans = 0;
  for (int r = 1; r <= 100 * 1000; r++) {
    // 範囲が決ま
    lint lb = a * r;
    lint rb = b * r;
    // [l, r]
    rb = min(rb, (lint)dp1.size() - 1);
    lint sum = acc.get(lb, rb + 1);
    ans += sum * dp2[r];

    ans %= MOD;

  }

  cout << ans << endl;
  return 0;
}
0