1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include<bits/stdc++.h> using namespace std; #define int long long const int MAXnd = 5e5; const int MAXn = 12; const int MAXeg = MAXnd * MAXn; const int INF = 0x3f3f3f3f3f3f3f3f;
template <typename T> inline void read(T &a) { register char c;while (c = getchar(), c < '0' || c > '9');register T x(c - '0');while (c = getchar(), c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);}a = x; } template <typename T, typename ...Argv> inline void read(T &n, Argv &...argv) { read(n), read(argv...); }
int head[MAXnd + 10], cntnex, nex[MAXeg + 10], to[MAXeg + 10], wei[MAXeg + 10]; inline void Insert(int u, int v, int w) { nex[++cntnex] = head[u]; head[u] = cntnex; to[cntnex] = v; wei[cntnex] = w; }
bool vis[MAXnd + 10]; int dis[MAXnd + 10]; priority_queue<pair<int, int>> q; void Dijkstra(int root, int rootdis) { memset(dis, 0x3f, sizeof(dis)); dis[root] = rootdis; q.push(make_pair(0, root)); while (!q.empty()) { int cur = q.top().second; q.pop(); if (vis[cur]) continue; vis[cur] = 1; for (int i = head[cur]; i; i = nex[i]) { if (dis[to[i]] > dis[cur] + wei[i]) { dis[to[i]] = dis[cur] + wei[i]; q.push(make_pair(-dis[to[i]], to[i])); } } } }
int n, l, r, a[MAXn + 10], ans; signed main() { read(n, l, r); for (int i = 1; i <= n; ++i) { read(a[i]); } sort(a + 1, a + 1 + n); for (int i = 0; i < a[1]; ++i) { for (int j = 2; j <= n; ++j) { Insert(i, (i + a[j]) % a[1], a[j]); } } Dijkstra(0, 0); for (int i = 0; i < a[1]; ++i) { if (dis[i] > r) continue; ans += (r - dis[i]) / a[1] + 1; if (dis[i] > l - 1) continue; ans -= (l - 1 - dis[i]) / a[1] + 1; } printf("%lld\n", ans); }
|