結果
| 問題 |
No.1043 直列大学
|
| コンテスト | |
| ユーザー |
koyopro
|
| 提出日時 | 2020-06-02 00:56:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,105 bytes |
| コンパイル時間 | 1,506 ms |
| コンパイル使用メモリ | 163,980 KB |
| 実行使用メモリ | 8,576 KB |
| 最終ジャッジ日時 | 2024-11-22 17:27:28 |
| 合計ジャッジ時間 | 5,740 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 WA * 7 RE * 15 |
ソースコード
#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];
int nr = j + R[i];
if (nr<MAX) DPR[nr] += DPR[j];
}
auto st = ST<int>(MAX,0,[](int a,int b){return a+b;});
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(A*j, B*j+1);
debug("j:%lld, DPR[j]:%lld, add:%lld\n", j, DPR[j],add);
ans += add;
}
cout << ans << endl;
}
koyopro