結果

問題 No.1043 直列大学
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-06-13 03:38:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 172,428 KB
実行使用メモリ 83,484 KB
最終ジャッジ日時 2023-08-24 12:50:33
合計ジャッジ時間 6,015 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,828 KB
testcase_01 AC 7 ms
6,048 KB
testcase_02 AC 15 ms
9,296 KB
testcase_03 AC 8 ms
6,032 KB
testcase_04 AC 8 ms
5,992 KB
testcase_05 AC 8 ms
6,176 KB
testcase_06 AC 8 ms
6,188 KB
testcase_07 AC 11 ms
7,640 KB
testcase_08 AC 11 ms
7,720 KB
testcase_09 AC 96 ms
44,276 KB
testcase_10 AC 114 ms
57,784 KB
testcase_11 AC 171 ms
79,048 KB
testcase_12 AC 185 ms
83,484 KB
testcase_13 AC 156 ms
81,572 KB
testcase_14 AC 164 ms
81,908 KB
testcase_15 AC 179 ms
80,724 KB
testcase_16 AC 162 ms
73,368 KB
testcase_17 AC 119 ms
60,300 KB
testcase_18 AC 119 ms
63,792 KB
testcase_19 AC 156 ms
80,792 KB
testcase_20 AC 115 ms
60,968 KB
testcase_21 AC 140 ms
79,012 KB
testcase_22 AC 146 ms
76,836 KB
testcase_23 AC 182 ms
82,604 KB
testcase_24 AC 131 ms
65,092 KB
testcase_25 AC 153 ms
73,536 KB
testcase_26 AC 164 ms
81,444 KB
testcase_27 AC 83 ms
51,596 KB
testcase_28 AC 151 ms
75,684 KB
testcase_29 AC 49 ms
28,696 KB
testcase_30 AC 116 ms
76,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int MAX = 1e5 + 1;

vector<ll> do_dp(vector<int> a) {
    int n = a.size();
    vector<vector<ll>> dp(n + 1, vector<ll>(MAX)); //dp[i] := i個目まで見た時にjを作る個数
    dp[0][0] = 1;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < MAX; j++) {
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= mod;
            if(j + a[i] < MAX) {
                dp[i + 1][j + a[i]] += dp[i][j];
                dp[i + 1][j + a[i]] %= mod;
            }
        }
    }
    return dp[n];
}

int main()
{
    int n, m; cin >> n >> m;
    vector<int> v(n), r(m);
    for(int i = 0; i < n; i++)cin >> v[i];
    for(int i = 0; i < m; i++)cin >> r[i];
    vector<ll> vnum = do_dp(v), rnum = do_dp(r);

    vector<ll> vsum(MAX + 1);
    for(int i = 0; i < MAX; i++) {
        vsum[i + 1] += vsum[i] + vnum[i];
        vsum[i + 1] %= mod;
    }

    ll a, b; cin >> a >> b;
    ll ans = 0;

    for(int i = 0; i < MAX; i++) {
        ll lef = i * a, rig = i * b + 1;
        lef = min((ll)MAX, lef);
        rig = min((ll)MAX, rig);
        ll res = rnum[i] * (vsum[rig] - vsum[lef]);
        res %= mod;
        ans += res;
        ans %= mod;
    }
    cout << ((ans -1) % mod + mod) % mod << endl;
}
0