結果

問題 No.1043 直列大学
ユーザー 山下山下
提出日時 2020-05-02 01:30:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,747 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 167,136 KB
実行使用メモリ 162,308 KB
最終ジャッジ日時 2023-08-26 19:44:11
合計ジャッジ時間 5,518 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,364 KB
testcase_01 AC 2 ms
5,420 KB
testcase_02 AC 3 ms
11,680 KB
testcase_03 AC 2 ms
5,372 KB
testcase_04 AC 2 ms
5,536 KB
testcase_05 AC 2 ms
5,456 KB
testcase_06 AC 1 ms
5,440 KB
testcase_07 AC 2 ms
7,488 KB
testcase_08 AC 3 ms
7,476 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 AC 49 ms
142,096 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 31 ms
100,460 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 30 ms
100,548 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 20 ms
68,912 KB
testcase_28 WA -
testcase_29 AC 11 ms
42,808 KB
testcase_30 AC 38 ms
99,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

ll n, m, sumR, sumV;
ll R[100], V[100];


ll dpr[101][100005] = {};
ll dpv[101][100005] = {};

void dpR() {
  for (int i = 0; i < m; i++) {
    for (int j = 0; j <= sumR; j++) {
      if (i == 0) {
        if (j == 0) dpr[i][j] = 1;
        else if (j == R[i]) dpr[i][j] = 1;
        else dpr[i][j] = 0;
      }
      else if (j < R[i]) dpr[i][j] = dpr[i-1][j];
      else dpr[i][j] = dpr[i-1][j] + dpr[i-1][j-R[i]];
    }
  }
}

void dpV() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= sumV; j++) {
      if (i == 0) {
        if (j == 0) dpv[i][j] = 1;
        else if (j == V[i]) dpv[i][j] = 1;
        else dpv[i][j] = 0;
      }
      else if (j < V[i]) dpv[i][j] = dpv[i-1][j];
      else dpv[i][j] = dpv[i-1][j] + dpv[i-1][j-V[i]];
    }
  }
}


int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> V[i];
    sumV += V[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> R[i];
    sumR += R[i];
  }
  
  dpR();
  dpV();
  vector<ll> sv(sumV+1);
  sv[0] = 0;
  vector<ll> sr(sumR+1);
  sr[0] = 0;
  for (int i = 1; i < sumV + 1; i++) sv[i] = sv[i-1] + dpv[n-1][i];
  for (int i = 1; i < sumR + 1; i++) sr[i] = sr[i-1] + dpr[m-1][i];
  
  int a, b;
  cin >> a >> b;
  
  ll count = 0;
  for (int i = 1; i < sumR + 1; i++) {
    if (dpr[m-1][i] > 0) {
      ll A = a * i;
      ll B = b * i;
      A--;
      if (A < sumV) {
        count += (dpr[m-1][i] * (sv[min(sumV, B)] - sv[A]));
        count %= mod;
      }
    }
  }
  cout << count <<endl;
}
0