# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1059012 | Thanhs | Magneti (COCI21_magneti) | C++14 | 136 ms | 237500 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define double long double
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define fi first
#define se second
#define all(x) x.begin(), x.end()
// mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int NM = 50 + 5;
const int LM = 1e4 + 5;
const int mod = 1e9 + 7;
struct mi
{
int v;
mi() : v(0){}
mi(int v) : v(v)
{
if (v >= mod)
v -= mod;
}
mi operator+(const mi& o)
{
return mi(v + o.v);
}
mi operator-(const mi& o)
{
return mi(v + mod - o.v);
}
mi operator*(const mi& o)
{
return mi(1ll * v * o.v % mod);
}
mi& operator+=(const mi &o)
{
v += o.v;
if (v >= mod)
v -= mod;
return *this;
}
mi& operator-=(const mi &o)
{
v += mod - o.v;
if (v >= mod)
v -= mod;
return *this;
}
mi& operator*=(const mi& o)
{
v = 1ll * v * o.v % mod;
return *this;
}
}fact[LM], invfact[LM], dp[NM][NM][LM], ans;
mi C(int n, int k)
{
if (k < 0 || k > n)
return mi(0);
return fact[n] * invfact[k] * invfact[n - k];
}
int n, l, a[NM];
mi bp(mi x, int y)
{
mi res(1);
while (y)
{
if (y & 1)
res = res * x;
x = x * x;
y >>= 1;
}
return res;
}
void pre()
{
fact[0].v = 1;
for (int i = 1; i < LM; i++)
fact[i] = fact[i - 1] * mi(i);
invfact[LM - 1] = bp(fact[LM - 1], mod - 2);
for (int i = LM - 1; i >= 1; i--)
invfact[i - 1] = invfact[i] * mi(i);
}
void solve()
{
if (n > 10)
return;
pre();
cin >> n >> l;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
a[i]--;
}
sort(a + 1, a + 1 + n);
dp[0][0][0].v = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j <= i; j++)
for (int k = 0; k <= l; k++)
if (dp[i][j][k].v)
{
dp[i + 1][j + 1][k] += dp[i][j][k];
if (k + a[i + 1] <= l)
dp[i + 1][j][k + a[i + 1]] += mi(j) * mi(2) * dp[i][j][k];
if (j && k + 2 * a[i + 1] <= l)
dp[i + 1][j - 1][k + 2 * a[i + 1]] += mi(j) * mi(j - 1) * dp[i][j][k];
}
for (int i = 0; i <= l; i++)
ans += dp[n][1][i] * C(l - i, n);
cout << ans.v;
}
signed main()
{
fastIO
if (fopen("in.txt", "r"))
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
int tc = 1;
// cin >> tc;
while (tc--)
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |