# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
974076 | VinhLuu | Magneti (COCI21_magneti) | C++17 | 124 ms | 8788 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.
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
const int N = 1e4 + 5;
const int mod = 1e9 + 7;
int n, l, ft[N], inv[N], f[2][55][N], ans, a[N];
void get(int &x,int y){
x = (x + y) % mod;
}
int lt(int u,int v){
if(v == 0) return 1;
int x = u;
int kq = 1;
while(v){
if(v & 1) kq = kq * x % mod;
x = x * x % mod;
v /= 2;
}
return kq;
}
void pre(){
int full = 1e4;
ft[0] = 1;
inv[0] = 1;
for(int i = 1; i <= full; i ++){
ft[i] = ft[i - 1] * i % mod;
inv[i] = inv[i - 1] * lt(i, mod - 2) % mod;
}
}
int C(int u,int v){
if(u == v || u == 0) return 1;
return ft[v] * inv[v - u] % mod * inv[u] % mod;
}
void sub1(){
int d = (n - 1) * a[1] + 1;
cout << ft[n] * C(n, l - d + n) % mod;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
pre();
cin >> n >> l;
for(int i = 1; i <= n; i ++) cin >> a[i];
sort(a + 1, a + n + 1);
if(a[n] == a[1]){
sub1();
return 0;
}
int pre = 0, nx = 1;
f[0][0][0] = 1;
for(int i = 1; i <= n; i ++){
f[nx][0][0] = 0;
for(int j = 1; j <= i; j ++){
for(int k = 1; k <= l; k ++){
f[nx][j][k] = f[pre][j - 1][k - 1];
if(k >= a[i]) get(f[nx][j][k], f[pre][j][k - a[i]] * j % mod * 2 % mod);
if(k >= 2 * a[i] - 1) get(f[nx][j][k], f[pre][j + 1][k - 2 * a[i] + 1] * j % mod * (j + 1) % mod);
// cout << pre << " " << nx << " " << i << " " << j << " " << k << " " << f[nx][j][k] << " f\n";
}
}
swap(pre, nx);
}
for(int i = 1; i <= l; i ++){
// cout << 1 << " " << i << " " << f[pre][1][i] << " g\n";
get(ans, f[pre][1][i] * C(n, l - i + n) % mod);
}
cout << ans;
}
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... |