結果

問題 No.1043 直列大学
ユーザー noriocnorioc
提出日時 2020-05-02 04:08:26
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,237 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 161,624 KB
実行使用メモリ 6,648 KB
最終ジャッジ日時 2023-09-04 07:38:24
合計ジャッジ時間 5,213 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,592 KB
testcase_01 AC 3 ms
5,856 KB
testcase_02 AC 5 ms
4,568 KB
testcase_03 AC 4 ms
5,840 KB
testcase_04 AC 4 ms
4,536 KB
testcase_05 AC 4 ms
4,576 KB
testcase_06 AC 4 ms
6,108 KB
testcase_07 AC 4 ms
4,620 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 14 ms
4,380 KB
testcase_28 WA -
testcase_29 AC 10 ms
4,580 KB
testcase_30 AC 19 ms
4,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

const MOD = 10^^9 + 7;

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

    // dp1[i] = 電圧の和が i となる組み合わせの数
    auto dp1 = new int[N];
    // dp2[i] = 抵抗の和が i となる組み合わせの数
    auto dp2 = new int[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]];
        }
    }
    foreach (i; 0..r.length) {
        for (int j = N-1; j >= r[i]; j--) {
            dp2[j] += dp2[j - r[i]];
        }
    }

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

    int ans = 0;
    foreach (i; 1..N) {
        int lo = min(N, a * i);
        int hi = min(N, b * i + 1);
        ans = (ans + dp2[i] * (acc[hi] - acc[lo])) % 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