結果

問題 No.1043 直列大学
ユーザー renjyaku_intrenjyaku_int
提出日時 2020-05-02 19:01:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 522 ms / 2,000 ms
コード長 2,479 bytes
コンパイル時間 3,855 ms
コンパイル使用メモリ 168,008 KB
実行使用メモリ 34,388 KB
最終ジャッジ日時 2023-08-24 12:44:11
合計ジャッジ時間 12,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
34,168 KB
testcase_01 AC 25 ms
34,320 KB
testcase_02 AC 46 ms
34,160 KB
testcase_03 AC 25 ms
34,360 KB
testcase_04 AC 26 ms
34,172 KB
testcase_05 AC 24 ms
34,360 KB
testcase_06 AC 25 ms
34,368 KB
testcase_07 AC 36 ms
34,172 KB
testcase_08 AC 37 ms
34,192 KB
testcase_09 AC 272 ms
34,184 KB
testcase_10 AC 324 ms
34,172 KB
testcase_11 AC 481 ms
34,312 KB
testcase_12 AC 522 ms
34,388 KB
testcase_13 AC 441 ms
34,184 KB
testcase_14 AC 466 ms
34,164 KB
testcase_15 AC 507 ms
34,284 KB
testcase_16 AC 454 ms
34,384 KB
testcase_17 AC 335 ms
34,172 KB
testcase_18 AC 337 ms
34,180 KB
testcase_19 AC 431 ms
34,168 KB
testcase_20 AC 328 ms
34,336 KB
testcase_21 AC 398 ms
34,384 KB
testcase_22 AC 415 ms
34,168 KB
testcase_23 AC 521 ms
34,168 KB
testcase_24 AC 367 ms
34,148 KB
testcase_25 AC 436 ms
34,232 KB
testcase_26 AC 464 ms
34,320 KB
testcase_27 AC 233 ms
34,164 KB
testcase_28 AC 427 ms
34,188 KB
testcase_29 AC 147 ms
34,200 KB
testcase_30 AC 324 ms
34,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<ll> v, r;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    v.resize(n);
    r.resize(m);
    rep(i, n) cin >> v[i];
    rep(i, m) cin >> r[i];
    ll a, b;
    cin >> a >> b;
    vector<ll> dpv(1000001, 0), dpr(1000001, 0), sumv(1000001, 0), sumr(1000001, 0);
    dpv[0] = 1;
    dpr[0] = 1;
    rep(i, n)
    {
        for (int j = 1000000; j >= 0; j--)
        {
            if (j + v[i] <= 1000000)
            {
                dpv[j + v[i]] += dpv[j];
                dpv[j + v[i]] %= MOD;
            }
        }
    }
    rep(i, m)
    {
        for (int j = 1000000; j >= 0; j--)
        {
            if (j + r[i] <= 1000000)
            {
                dpr[j + r[i]] += dpr[j];
                dpr[j + r[i]] %= MOD;
            }
        }
    }
    ll sum_r = 0;
    ll sum_v = 0;
    for (int i = 1; i <= 1000000; i++)
    {
        sum_r += dpr[i];
        sum_r %= MOD;
        sum_v += dpv[i];
        sum_v %= MOD;
        sumr[i] = sum_r;
        sumv[i] = sum_v;
    }
    ll ans=0;
    for (ll i = 1; i <= 1000000; i++){
        if(dpr[i]){
            ll maxv=min(b*i,ll(1000000));
            ll minv=min(a*i-1,ll(1000000));
            ans+=dpr[i]*((sumv[maxv]-sumv[minv]+MOD)%MOD);
            ans%=MOD;
        }
    }
    cout<<ans<<"\n";
}
0