結果
問題 | No.1043 直列大学 |
ユーザー | wk |
提出日時 | 2020-05-02 12:46:12 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 6,338 bytes |
コンパイル時間 | 1,511 ms |
コンパイル使用メモリ | 171,104 KB |
実行使用メモリ | 7,520 KB |
最終ジャッジ日時 | 2024-06-02 03:13:13 |
合計ジャッジ時間 | 2,991 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
7,332 KB |
testcase_01 | AC | 4 ms
7,376 KB |
testcase_02 | AC | 5 ms
7,388 KB |
testcase_03 | AC | 4 ms
7,388 KB |
testcase_04 | AC | 4 ms
7,360 KB |
testcase_05 | AC | 4 ms
7,388 KB |
testcase_06 | AC | 4 ms
7,392 KB |
testcase_07 | AC | 5 ms
7,232 KB |
testcase_08 | AC | 4 ms
7,260 KB |
testcase_09 | AC | 22 ms
7,392 KB |
testcase_10 | AC | 25 ms
7,260 KB |
testcase_11 | AC | 34 ms
7,484 KB |
testcase_12 | AC | 42 ms
7,392 KB |
testcase_13 | AC | 34 ms
7,388 KB |
testcase_14 | AC | 36 ms
7,520 KB |
testcase_15 | AC | 41 ms
7,296 KB |
testcase_16 | AC | 37 ms
7,392 KB |
testcase_17 | AC | 26 ms
7,384 KB |
testcase_18 | AC | 27 ms
7,320 KB |
testcase_19 | AC | 35 ms
7,388 KB |
testcase_20 | AC | 25 ms
7,320 KB |
testcase_21 | AC | 32 ms
7,360 KB |
testcase_22 | AC | 33 ms
7,388 KB |
testcase_23 | AC | 43 ms
7,516 KB |
testcase_24 | AC | 30 ms
7,324 KB |
testcase_25 | AC | 34 ms
7,384 KB |
testcase_26 | AC | 37 ms
7,376 KB |
testcase_27 | AC | 20 ms
7,388 KB |
testcase_28 | AC | 34 ms
7,332 KB |
testcase_29 | AC | 13 ms
7,260 KB |
testcase_30 | AC | 29 ms
7,376 KB |
ソースコード
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; (i) < (n); (i)++) #define INF 5000000000000000 using namespace std; struct Edge{ int to; long weight; Edge(int t, long w) : to(t), weight(w) {} }; long modpow(long a, long n, long mod) { long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long modinv(long a, long mod) { return modpow(a, mod - 2, mod); } struct compare1 { bool operator()(const pair<long, long>& value, const long& key) { return (value.first < key); } bool operator()(const long& key, const pair<long, long>& value) { return (key < value.first); } }; struct RMQ { vector<int> a; int inf = 2000000000; // 2*10^9 int n = 1; RMQ(int n_ = 1){ init(n_); } void init(int n_ = 1){ while(n < n_) n *= 2; a.resize(2*n-1); REP(i, 2*n-1) a[i] = inf; } //k番目の値(0-indexed)をbに変更 void update(int k, int b){ k += n-1; a[k] = b; while(k > 0){ k = (k-1)/2; a[k] = min(a[2*k+1], a[2*k+2]); } } //[a,b)の最小値を返す際に呼ぶ関数 int query_first(int c, int b){ return query(c, b, 0, 0, n); } //k : 節点番号, l, rはその接点が[l, r)に対応することを示す int query(int c, int b, int k, int l, int r){ if(r <= c || b <= l) return inf; if(c <= l && r <= b) return a[k]; else{ int vl = query(c, b, k*2+1, l, (l+r)/2); int vr = query(c, b, k*2+2, (l+r)/2, r); return min(vl, vr); } } }; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int n = 1){ init(n); } void init(int n = 1){ par.resize(n); rank.resize(n); REP(i, n) par[i] = i, rank[i] = 0; } int root(int x){ if(par[x] == x) return x; else return par[x] = root(par[x]); } bool issame(int x, int y){ return root(x) == root(y); } bool merge(int x, int y){ x = root(x); y = root(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x, y); if(rank[x] == rank[y]) rank[x]++; par[y] = x; return true; } }; template<class Abel> struct weightedUnionFind{ vector<int> par; vector<int> rank; vector<Abel> diff_weight; weightedUnionFind(int n = 1, Abel SUM_UNITY = 0){ init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0){ par.resize(n); rank.resize(n); diff_weight.resize(n); REP(i, n) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x){ if(par[x] == x) return x; else{ int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x){ root(x); return diff_weight[x]; } bool issame(int x, int y){ return root(x) == root(y); } bool merge(int x, int y, Abel w){ w += weight(x); w -= weight(y); x = root(x); y = root(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x, y), w = -w; if(rank[x] == rank[y]) rank[x]++; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y){ return weight(y) - weight(x); } }; using Graph = vector<vector<int>>; using P = pair<long, long>; /* void dijkstra(int s, int V, Graph &G, long* d){ priority_queue<P, vector<P>, greater<P>> pque; fill(d, d + V, INF); d[s] = 0; pque.push(P(0, s)); while(!pque.empty()){ P p = pque.top(); pque.pop(); int now = p.second; if(d[now] < p.first) continue; REP(i, G[now].size()){ Edge e = G[now][i]; if(d[e.to] > d[now] + e.weight){ d[e.to] = d[now] + e.weight; pque.push(P(d[e.to], e.to)); } } } } */ int GCD(int a, int b){ if(b == 0) return a; if(a < b) return GCD(b, a); else return GCD(b, a%b); } struct BIT{ vector<long> dat; int n = 1; BIT(int nn = 1){ init(nn); } void init(int nn = 1){ while(n < nn) n *= 2; dat.resize(n+1); REP(i, n+1) dat[i] = 0l; } //1-indexed!!!! void add(int i, long x){ while(i <= n){ dat[i] += x; i += (i&(-i)); } } //1-indexed!!!!! long get_sum(int i){ long ans = 0l; while(i > 0){ ans += dat[i]; i -= (i & (-i)); } return ans; } }; int main() { int N, M; cin >> N >> M; long V[105], R[105]; REP(i, N) cin >> V[i]; REP(i, M) cin >> R[i]; long A, B; cin >> A >> B; long dpR1[100005], dpR2[100005], dpV1[100005], dpV2[100005]; long mod = 1000000007; REP(i, 100005) dpR1[i] = 0l, dpV1[i] = 0l; REP(i, N){ REP(j, 100005) dpV2[j] = dpV1[j]; REP(j, 100001){ if(dpV1[j]!=0l){ dpV2[(long)j+V[i]] += dpV1[j]; dpV2[(long)j+V[i]] %= mod; } } dpV2[V[i]]++; dpV2[V[i]] %= mod; REP(j, 100005) dpV1[j] = dpV2[j]; //REP(i, 20) cout << i << " " << dpV1[i] << endl; } REP(i, M){ REP(j, 100005) dpR2[j] = dpR1[j]; REP(j, 100001){ if(dpR1[j]!=0l){ dpR2[(long)j+R[i]] += dpR1[j]; dpR2[(long)j+R[i]] %= mod; } } dpR2[R[i]]++; dpR2[R[i]] %= mod; REP(j, 100005) dpR1[j] = dpR2[j]; //REP(i, 20) cout << i << " " << dpR1[i] << endl; } long sumV[100005]; sumV[0]=0l; REP(i, 100001){ sumV[i+1] = sumV[i] + dpV1[i+1]; sumV[i+1] %= mod; } long ans = 0l; for(long i=1; i<=100000l; i++){ if(A*i <= 100000l){ long temp = sumV[min(100000l, B*i)] - sumV[A*i-1]; if(temp < 0l) temp += mod; temp *= dpR1[i]; temp %= mod; ans += temp; ans %= mod; } } cout << ans << endl; return 0; }