結果

問題 No.1043 直列大学
ユーザー taklimonetaklimone
提出日時 2020-05-01 22:00:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 1,472 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 198,456 KB
実行使用メモリ 42,680 KB
最終ジャッジ日時 2023-08-24 05:42:49
合計ジャッジ時間 9,815 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
42,376 KB
testcase_01 AC 21 ms
30,152 KB
testcase_02 AC 49 ms
42,440 KB
testcase_03 AC 21 ms
30,116 KB
testcase_04 AC 21 ms
30,332 KB
testcase_05 AC 21 ms
30,112 KB
testcase_06 AC 20 ms
30,212 KB
testcase_07 AC 40 ms
42,496 KB
testcase_08 AC 41 ms
42,380 KB
testcase_09 AC 211 ms
42,360 KB
testcase_10 AC 245 ms
42,444 KB
testcase_11 AC 356 ms
42,644 KB
testcase_12 AC 389 ms
42,512 KB
testcase_13 AC 327 ms
42,412 KB
testcase_14 AC 343 ms
42,436 KB
testcase_15 AC 376 ms
42,496 KB
testcase_16 AC 339 ms
42,412 KB
testcase_17 AC 254 ms
42,396 KB
testcase_18 AC 255 ms
42,400 KB
testcase_19 AC 321 ms
42,408 KB
testcase_20 AC 248 ms
42,680 KB
testcase_21 AC 298 ms
42,420 KB
testcase_22 AC 315 ms
42,632 KB
testcase_23 AC 384 ms
42,380 KB
testcase_24 AC 279 ms
42,436 KB
testcase_25 AC 325 ms
42,436 KB
testcase_26 AC 346 ms
42,436 KB
testcase_27 AC 181 ms
42,632 KB
testcase_28 AC 319 ms
42,444 KB
testcase_29 AC 121 ms
42,436 KB
testcase_30 AC 247 ms
42,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N, M;
long long V[110], R[100];
long long A, B;
long long v[2][1001001] = {}, r[2][1001001] = {}, sum[1001001] = {};
long long const mod = 1000000007;

void dp() {
    v[0][0] = true;
    for(int i=1; i<=N; ++i) {
        for(int j=0; j<=1000000; ++j) {
            if(j < V[i]) v[i & 1][j] = v[(i - 1) & 1][j];
            else v[i & 1][j] = (v[(i - 1) & 1][j] + v[(i - 1) & 1][j - V[i]]) % mod;
        }
    }

    r[0][0] = true;
    for(int i=1; i<=M; ++i) {
        for(int j=0; j<=1000000; ++j) {
            if(j < R[i]) r[i & 1][j] = r[(i - 1) & 1][j];
            else r[i & 1][j] = (r[(i - 1) & 1][j] + r[(i - 1) & 1][j - R[i]]) % mod;
        }
    }
}

void takesum() {
    for(int j=1; j<=1000000; ++j) {
        sum[j] = (sum[j - 1] + v[N & 1][j]) % mod;
    }
}

long long cnt(long long l, long long r) {
    if(l == 0 || r == 0) return 0;
    r = min(r, 1000000LL);
    l = min(l, 1000000LL);
    long long ret = sum[r] - sum[l - 1];
    if(ret < 0) ret = (ret + mod) % mod;
    return ret;
}

long long solve() {
    long long ret = 0;
    for(int j=1; j<=1000000; ++j) {
        long long s = r[M & 1][j];
        long long t = cnt(A * j, B * j);
        ret = (ret + s * t % mod) % mod;
    }
    return ret;
}

int main() {
    cin >> N >> M;
    for(int i=1; i<=N; ++i) cin >> V[i];
    for(int i=1; i<=M; ++i) cin >> R[i];
    cin >> A >> B;

    dp();
    takesum();
    cout << solve() << '\n';
}
0