https://www.mina.moe/BZPRO/JudgeOnline/2118.html

（最小是因为大的能取到的位置小的都能取到）

#include <bits/stdc++.h>

#define NS (15)
#define NNS (500005)
#define MS (6000005)

using namespace std;

typedef long long LL;
typedef pair<LL, int> PLI;

template<typename _Tp> inline void IN(_Tp& dig)
{
char c; bool flag = 0; dig = 0;
while (c = getchar(), !isdigit(c)) if (c == '-') flag = 1;
while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
if (flag) dig = -dig;
}

int n, A[NS];

LL L, R;

struct Graph
{
int head[NNS], nxt[MS], to[MS], w[MS], sz;
void push(int a, int b, int c)
{
nxt[sz] = head[a], to[sz] = b, w[sz] = c, head[a] = sz++;
}
} g;

priority_queue<PLI, vector<PLI>, greater<PLI> > pq;

LL dis[NNS];

bool book[NNS];

void Dij()
{
fill(dis + 1, dis + A[0], LLONG_MAX), pq.push(PLI(0, 0));
while (!pq.empty())
{
int a = pq.top().second; pq.pop();
if (book[a]) continue;
book[a] = 1;
for (int i = g.head[a]; ~i; i = g.nxt[i])
if (dis[a] + g.w[i] < dis[g[i]])
dis[g[i]] = dis[a] + g.w[i], pq.push(PLI(dis[g[i]], g[i]));
}
}

int main(int argc, char const* argv[])
{
IN(n), IN(L), IN(R);
for (int i = 0; i < n; i += 1) IN(A[i]);
nth_element(A, A, A + n), n--;
for (int i = 1; i <= n; i += 1)
for (int j = 0; j < A[0]; j += 1)
g.push(j, (j + A[i]) % A[0], A[i]);
Dij();
LL ans = 0;
for (int i = 0; i < A[0]; i += 1)
if (dis[i] <= R)
{
if (dis[i] >= L) ans += (R - dis[i]) / A[0] + 1;
else
{
ans += (R - dis[i]) / A[0];
ans -= (L - dis[i] - 1) / A[0];
}
}
printf("%lld\n", ans);
return 0;
}


Remmina

No puzzle that couldn't be solved.