結果

問題 No.1043 直列大学
ユーザー norioc
提出日時 2020-05-02 04:20:36
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,358 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 175,844 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 06:53:49
合計ジャッジ時間 3,968 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

const MOD = 10^^9 + 7;

long calc(int[] v, int[] r, int a, int b) {
    const N = 110000;

    // dp1[i] = 電圧の和が i となる組み合わせの数
    auto dp1 = new long[N];
    // dp2[i] = 抵抗の和が i となる組み合わせの数
    auto dp2 = new long[N];

    dp1[0] = dp2[0] = 1;
    foreach (i; 0..v.length) {
        for (int j = N-1; j >= v[i]; j--) {
            dp1[j] += dp1[j - v[i]];
            dp1[j] %= MOD;
        }
    }
    foreach (i; 0..r.length) {
        for (int j = N-1; j >= r[i]; j--) {
            dp2[j] += dp2[j - r[i]];
            dp2[j] %= MOD;
        }
    }

    auto acc = new long[N + 1];
    foreach (i; 0..N) acc[i+1] = (acc[i] + dp1[i]) % MOD;

    long ans = 0;
    foreach (i; 1..N) {
        auto lo = min(N, cast(long)a * i);
        auto hi = min(N, cast(long)b * i + 1);
        auto x = (acc[hi] - acc[lo] + MOD) % MOD;
        ans = (ans + dp2[i] * x) % MOD;
    }
    return ans;
}

void main() {
    int n, m; scan(n, m);
    auto v = readints;
    auto r = readints;
    int a, b; scan(a, b);
    writeln(calc(v, r, a, b));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
0