結果

問題 No.1043 直列大学
ユーザー koyoprokoyopro
提出日時 2020-06-02 01:06:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 4,179 bytes
コンパイル時間 2,560 ms
コンパイル使用メモリ 150,940 KB
実行使用メモリ 6,904 KB
最終ジャッジ日時 2023-08-24 12:49:23
合計ジャッジ時間 7,338 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
6,760 KB
testcase_01 AC 35 ms
6,716 KB
testcase_02 AC 44 ms
6,668 KB
testcase_03 AC 35 ms
6,676 KB
testcase_04 AC 35 ms
6,688 KB
testcase_05 AC 35 ms
6,720 KB
testcase_06 AC 36 ms
6,724 KB
testcase_07 AC 40 ms
6,696 KB
testcase_08 AC 40 ms
6,692 KB
testcase_09 AC 139 ms
6,876 KB
testcase_10 AC 161 ms
6,640 KB
testcase_11 AC 226 ms
6,724 KB
testcase_12 AC 254 ms
6,904 KB
testcase_13 AC 208 ms
6,816 KB
testcase_14 AC 219 ms
6,696 KB
testcase_15 AC 237 ms
6,664 KB
testcase_16 AC 215 ms
6,724 KB
testcase_17 AC 165 ms
6,724 KB
testcase_18 AC 171 ms
6,644 KB
testcase_19 AC 205 ms
6,876 KB
testcase_20 AC 162 ms
6,816 KB
testcase_21 AC 191 ms
6,720 KB
testcase_22 AC 199 ms
6,724 KB
testcase_23 AC 242 ms
6,872 KB
testcase_24 AC 179 ms
6,724 KB
testcase_25 AC 206 ms
6,692 KB
testcase_26 AC 218 ms
6,688 KB
testcase_27 AC 131 ms
6,760 KB
testcase_28 AC 204 ms
6,716 KB
testcase_29 AC 86 ms
6,664 KB
testcase_30 AC 162 ms
6,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 10
int MAX=1e5+10;
#else
#define SIZE 123
int MAX=1e5+10;
#endif

int N,M,V[SIZE],R[SIZE],A,B;
int MOD=1e9+7;
vector<int> DPV(MAX,0),DPR(MAX,0);

template<typename T> class ST {
    using F = function<T(T, T)>;
    int size;
    T init;
    F f;
    vector<T> seg;
    int depth = 0;
    
public: ST(int size, T init, F f): size(size), init(init), f(f) {
    while (1<<depth < size) depth++;
    seg.assign(2<<depth, init);
}
    
    void update(int k, T t) {
        k += 1 << depth;
        seg[k] = t;
        while(k>>=1) seg[k] = f(seg[2*k], seg[2*k+1]);
    }
    
    T query(int a, int b) {
        a += 1<<depth;
        b += 1<<depth;
        T l = init;
        T r = init;
        while(a < b) {
            if (a & 1) l = f(l, seg[a++]);
            if (b & 1) r = f(r, seg[--b]);
            a >>= 1;
            b >>= 1;
        }
        return f(l, r);
    }
    
    T operator[] (int k) {
        return seg[k + (1<<depth)];
    }
};

template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

void solve() {
    cin>>N>>M;
    REP(i,N)cin>>V[i];
    REP(i,M)cin>>R[i];
    cin>>A>>B;
    DPV[0]=1;
    DPR[0]=1;
    REP(i,N)RREP(j,MAX) {
        int nv = j + V[i];
        if (nv<MAX) (DPV[nv] += DPV[j])%=MOD;
    }
    REP(i,M)RREP(j,MAX) {
        int nr = j + R[i];
        if (nr<MAX) (DPR[nr] += DPR[j])%=MOD;
    }
    auto st = ST<int>(MAX,0,[](int a,int b){return (a+b)%MOD;});
    REP(j,MAX) {
        st.update(j, DPV[j]);
    }
    mint ans = 0;
    REP(j, MAX-1) if (j&&DPR[j]) {
        int add = DPR[j] * st.query(min(A*j,MAX-5), min(B*j+1,MAX-5));
        debug("j:%lld, DPR[j]:%lld, add:%lld\n", j, DPR[j],add);
        ans += add;
    }
    cout << ans << endl;
}

0