結果

問題 No.1043 直列大学
ユーザー kilalakilala
提出日時 2020-05-02 00:39:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 2,779 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 181,156 KB
実行使用メモリ 18,124 KB
最終ジャッジ日時 2023-08-24 12:37:18
合計ジャッジ時間 7,429 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,600 KB
testcase_01 AC 3 ms
4,500 KB
testcase_02 AC 3 ms
4,440 KB
testcase_03 AC 3 ms
4,676 KB
testcase_04 AC 3 ms
4,528 KB
testcase_05 AC 3 ms
4,504 KB
testcase_06 AC 3 ms
4,524 KB
testcase_07 AC 3 ms
4,496 KB
testcase_08 AC 3 ms
4,540 KB
testcase_09 AC 10 ms
5,208 KB
testcase_10 AC 18 ms
5,388 KB
testcase_11 AC 26 ms
5,668 KB
testcase_12 AC 434 ms
18,124 KB
testcase_13 AC 268 ms
12,720 KB
testcase_14 AC 289 ms
13,088 KB
testcase_15 AC 357 ms
14,436 KB
testcase_16 AC 288 ms
13,872 KB
testcase_17 AC 156 ms
10,492 KB
testcase_18 AC 134 ms
9,980 KB
testcase_19 AC 262 ms
12,404 KB
testcase_20 AC 143 ms
10,040 KB
testcase_21 AC 231 ms
12,020 KB
testcase_22 AC 245 ms
12,180 KB
testcase_23 AC 376 ms
14,276 KB
testcase_24 AC 172 ms
10,628 KB
testcase_25 AC 260 ms
12,440 KB
testcase_26 AC 288 ms
12,720 KB
testcase_27 AC 97 ms
9,200 KB
testcase_28 AC 158 ms
10,016 KB
testcase_29 AC 11 ms
5,784 KB
testcase_30 AC 245 ms
11,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <functional>  
#include <algorithm>  
#include <iostream>  
#include <fstream>  
#include <sstream>  
#include <iomanip>  
#include <numeric>  
#include <cstring>  
#include <cassert>  
#include <cstdio>  
#include <string>  
#include <vector>  
#include <bitset>  
#include <queue>  
#include <stack>  
#include <cmath>  
#include <ctime>  
#include <list>  
#include <set>  
#include <map>  
#include <bits/stdc++.h>

using namespace std;

#define PB push_back  
#define MP(A, B) make_pair(A, B)  
#define fi first  
#define se second  

#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define ll long long  
#define MAX 1000005  
#define MOD 1000000007  
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

int v[105] = {0}, r[105] = {0};
unordered_map<long long, ll> vp, rp;
unordered_map<long long, ll> vpa, rpa;
vector<ll> rpr(100005, 0), rprs(100005, 0);
vector<ll> vl, rl;
vector<ll> rls;
int main() {
    int n, m, a, b;
    long long ans = 0;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> v[i];
    for (int i = 0; i < m; ++i) cin >> r[i];
    cin >> a >> b;

    for (int i = 0; i < n; ++i) {
        vpa = vp;
        int vll = vl.size();
        long long vn = v[i];
        if (!vp.count(vn)) vl.push_back(vn);
        vpa[vn]++;
        vpa[vn] %= MOD;
        for (int j = 0; j < vll; ++j) {
            if (!vp.count(vn + vl[j])) {
                vl.push_back(vn + vl[j]);
            }
            vpa[vn+vl[j]] += vp[vl[j]];
            vpa[vn+vl[j]] %= MOD;
        }
        vp = vpa;
    }
    for (int i = 0; i < m; ++i) {
        rpa = rp;
        int rll = rl.size();
        ll rn = r[i];
        if (!rp.count(rn)) rl.push_back(rn);
        rpa[rn]++;
        rpa[rn] %= MOD;
        for (int j = 0; j < rll; ++j) {
            if (!rp.count(rn + rl[j])) {
                rl.push_back(rn + rl[j]);
            }
            rpa[rn+rl[j]]+=rp[rl[j]];
            rpa[rn+rl[j]] %= MOD;
        }
        rp = rpa;
    }

    for (auto &a:rl) rpr[a] = rp[a];
    rprs[0] = rpr[a];
    for (int i = 0; i <= 100000; ++i) rprs[i] = rprs[i-1] + rpr[i], rprs[i] %= MOD;

    for (int i = 0; i < vl.size(); ++i) {
        double lb = vl[i] / (double)b, hb = vl[i] / (double)a;
        int llb = ceil(lb), hhb = floor(hb);
        ans = ans + (vp[vl[i]] % MOD) * ((rprs[hhb] - rprs[llb-1] + MOD) % MOD) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0