Skip to content

Instantly share code, notes, and snippets.

@hikariyo
Created December 15, 2025 04:55
Show Gist options
  • Select an option

  • Save hikariyo/aa42683ed1013a740dbe264e02b4c0e0 to your computer and use it in GitHub Desktop.

Select an option

Save hikariyo/aa42683ed1013a740dbe264e02b4c0e0 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int P = 2004, N = 15;
int n, f[N];
map<int, int> F;
int C(int i) {
int fact = 1;
for (int j = 1; j <= n; j++) fact = fact * j;
int res = 1;
for (int j = 0; j < n; j++) res = (res * (n + i - j)) % (P * fact);
assert(res % fact == 0);
return res / fact;
}
int solve(int s) {
int res = 0;
for (const auto& [i, fi]: F) {
int m = s-i;
if (m < 0) continue;
res = (res + fi * C(m)) % P;
}
return res;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int a, b;
cin >> n >> a >> b;
for (int i = 0; i < n; i++) cin >> f[i];
for (int S = 0; S < 1 << n; S++) {
int idx = 0, val = 1;
for (int i = 0; i < n; i++) {
if (S >> i & 1) {
idx += f[i] + 1;
val = -val;
}
}
F[idx] = (F[idx] + P + val) % P;
}
cout << (solve(b) - solve(a-1) + P) % P << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment