結果

問題 No.1043 直列大学
ユーザー noriocnorioc
提出日時 2020-05-02 04:14:32
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,264 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 161,720 KB
実行使用メモリ 7,400 KB
最終ジャッジ日時 2023-09-04 07:38:51
合計ジャッジ時間 3,154 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,624 KB
testcase_01 AC 4 ms
5,832 KB
testcase_02 AC 6 ms
6,356 KB
testcase_03 AC 3 ms
5,836 KB
testcase_04 AC 4 ms
6,352 KB
testcase_05 AC 3 ms
5,844 KB
testcase_06 AC 4 ms
5,868 KB
testcase_07 AC 5 ms
5,840 KB
testcase_08 AC 4 ms
6,076 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 30 ms
5,844 KB
testcase_15 AC 32 ms
5,768 KB
testcase_16 AC 29 ms
6,096 KB
testcase_17 AC 22 ms
5,832 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 21 ms
6,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 15 ms
5,908 KB
testcase_28 WA -
testcase_29 AC 12 ms
6,592 KB
testcase_30 AC 22 ms
5,836 KB
権限があれば一括ダウンロードができます

ソースコード

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]];
        }
    }
    foreach (i; 0..r.length) {
        for (int j = N-1; j >= r[i]; j--) {
            dp2[j] += dp2[j - r[i]];
        }
    }

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

    long ans = 0;
    foreach (i; 1..N) {
        auto lo = min(N, cast(long)a * i);
        auto hi = min(N, cast(long)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