結果

問題 No.1043 直列大学
ユーザー Ricky_ponRicky_pon
提出日時 2019-11-13 17:22:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 166,408 KB
実行使用メモリ 165,132 KB
最終ジャッジ日時 2023-08-24 05:37:48
合計ジャッジ時間 4,658 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
14,556 KB
testcase_01 AC 5 ms
9,928 KB
testcase_02 AC 8 ms
18,524 KB
testcase_03 AC 5 ms
9,920 KB
testcase_04 AC 5 ms
9,896 KB
testcase_05 AC 5 ms
9,904 KB
testcase_06 AC 5 ms
9,892 KB
testcase_07 AC 7 ms
14,544 KB
testcase_08 AC 7 ms
14,620 KB
testcase_09 AC 38 ms
88,264 KB
testcase_10 AC 44 ms
102,416 KB
testcase_11 AC 68 ms
152,288 KB
testcase_12 AC 84 ms
165,132 KB
testcase_13 AC 66 ms
137,980 KB
testcase_14 AC 70 ms
147,184 KB
testcase_15 AC 78 ms
160,108 KB
testcase_16 AC 68 ms
142,816 KB
testcase_17 AC 50 ms
108,660 KB
testcase_18 AC 49 ms
106,656 KB
testcase_19 AC 65 ms
135,864 KB
testcase_20 AC 48 ms
104,596 KB
testcase_21 AC 60 ms
125,016 KB
testcase_22 AC 62 ms
130,684 KB
testcase_23 AC 80 ms
164,356 KB
testcase_24 AC 54 ms
116,860 KB
testcase_25 AC 65 ms
136,124 KB
testcase_26 AC 72 ms
145,792 KB
testcase_27 AC 35 ms
74,048 KB
testcase_28 AC 63 ms
134,772 KB
testcase_29 AC 21 ms
47,288 KB
testcase_30 AC 52 ms
104,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;

const lint mod = 1e9 + 7;
const lint INF = mod * mod;
const int MAX = 100010;

lint dpv[110][MAX], dpr[110][MAX];

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int v[n], r[m];
    rep(i, n) scanf("%d", &v[i]);
    rep(i, m) scanf("%d", &r[i]);
    lint a, b;
    scanf("%lld%lld", &a, &b);

    rep(i, n+1)rep(j, MAX) dpv[i][j] = 0;
    rep(i, m+1)rep(j, MAX) dpr[i][j] = 0;
    dpv[0][0] = 1;
    rep(i, n)rep(j, MAX)if(dpv[i][j]){
        (dpv[i+1][j] += dpv[i][j]) %= mod;
        if(j+v[i] < MAX) (dpv[i+1][j+v[i]] += dpv[i][j]) %= mod;
    }
    dpr[0][0] = 1;
    rep(i, m)rep(j, MAX)if(dpr[i][j]){
        (dpr[i+1][j] += dpr[i][j]) %= mod;
        if(j+r[i] < MAX) (dpr[i+1][j+r[i]] += dpr[i][j]) %= mod;
    }

    lint vsum[MAX];
    vsum[0] = 0;
    rep(i, MAX-1) vsum[i+1] = (vsum[i] + dpv[n][i]) % mod;

    lint ans = 0;
    For(i, 1, MAX)if(dpr[m][i]){
        lint L = a*(lint)i, R = b*(lint)i + 1;
        if(L > MAX) break;
        (ans += (vsum[min(R, (lint)MAX-1)] - vsum[L] + mod) % mod * dpr[m][i]) %= mod;
    }
    printf("%lld\n", ans);
}
0