結果

問題 No.1043 直列大学
ユーザー StrorkisStrorkis
提出日時 2020-05-02 01:00:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 70,936 KB
実行使用メモリ 4,900 KB
最終ジャッジ日時 2023-08-24 12:37:45
合計ジャッジ時間 2,517 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,900 KB
testcase_01 AC 4 ms
4,564 KB
testcase_02 AC 5 ms
4,660 KB
testcase_03 AC 4 ms
4,612 KB
testcase_04 AC 4 ms
4,568 KB
testcase_05 AC 4 ms
4,608 KB
testcase_06 AC 4 ms
4,624 KB
testcase_07 AC 5 ms
4,560 KB
testcase_08 AC 5 ms
4,660 KB
testcase_09 AC 21 ms
4,608 KB
testcase_10 AC 24 ms
4,608 KB
testcase_11 AC 34 ms
4,608 KB
testcase_12 AC 37 ms
4,684 KB
testcase_13 AC 32 ms
4,620 KB
testcase_14 AC 33 ms
4,568 KB
testcase_15 AC 36 ms
4,664 KB
testcase_16 AC 32 ms
4,660 KB
testcase_17 AC 25 ms
4,612 KB
testcase_18 AC 25 ms
4,560 KB
testcase_19 AC 31 ms
4,624 KB
testcase_20 AC 24 ms
4,720 KB
testcase_21 AC 29 ms
4,560 KB
testcase_22 AC 30 ms
4,564 KB
testcase_23 AC 37 ms
4,564 KB
testcase_24 AC 27 ms
4,604 KB
testcase_25 AC 31 ms
4,556 KB
testcase_26 AC 33 ms
4,620 KB
testcase_27 AC 18 ms
4,608 KB
testcase_28 AC 31 ms
4,680 KB
testcase_29 AC 12 ms
4,664 KB
testcase_30 AC 24 ms
4,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

const long long MOD = 1000000007;
const long long DP_MAX = 100000;

int main() {
    int N, M;
    std::cin >> N >> M;

    std::vector<int> V(N), R(M);
    for (int i = 0; i < N; i++) std::cin >> V[i];
    for (int i = 0; i < M; i++) std::cin >> R[i];

    long long A, B;
    std::cin >> A >> B;

    std::vector<long long> dp_V(DP_MAX + 1), dp_R(DP_MAX + 1);
    dp_V[0] = dp_R[0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = DP_MAX; j >= 0; j--) {
            if (j + V[i] <= DP_MAX) {
                dp_V[j + V[i]] += dp_V[j];
                dp_V[j + V[i]] %= MOD;
            }
        }
    }
    for (int i = 0; i < M; i++) {
        for (int j = DP_MAX; j >= 0; j--) {
            if (j + R[i] <= DP_MAX) {
                dp_R[j + R[i]] += dp_R[j];
                dp_R[j + R[i]] %= MOD;
            }
        }
    }

    for (int i = 0; i < DP_MAX; i++) {
        dp_V[i + 1] += dp_V[i];
        dp_V[i + 1] %= MOD;
    }

    long long ans = 0;
    for (long long i = 1; i <= DP_MAX; i++) {
        long long left = i * A - 1;
        if (left > DP_MAX) break;
        long long right = std::min(DP_MAX, i * B);
        ans += (dp_V[right] - dp_V[left] + MOD) * dp_R[i] % MOD;
        ans %= MOD;
    }
    std::cout << ans << "\n";
}
0