# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892359 | tradz | Magneti (COCI21_magneti) | C++14 | 1065 ms | 4596 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 For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())
using namespace std;
const int N = 1e6+7;
const int M = 1e9+7;
const ll oo = 3e18;
ll gt[N], igt[N];
int n, l;
ll poww(ll a, ll b) {
if(b == 0) return 1;
ll t = poww(a, b / 2);
t = t * t % M;
if(b & 1) t = t * a % M;
return t;
}
ll ncr(ll nn, ll rr) {
if (rr > nn || rr < 0) return 0;
return ((gt[nn] * igt[rr]) % M * igt[nn - rr]) % M;
}
ii a[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
#define TASK ""
if (fopen (".inp", "r")) {
freopen (".inp", "r", stdin);
freopen (".out", "w", stdout);
}
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
cin >> n >> l;
For(i, 1, n) cin >> a[i].fi, a[i].se = i;
gt[0] = gt[1] = 1;
For(i, 2, l) gt[i] = (i * gt[i - 1]) % M;
igt[l] = poww(gt[l], M - 2);
Ford(i, l - 1, 0) igt[i] = (igt[i + 1] * (i + 1)) % M;
sort(a + 1, a + n + 1);
ll ans = 0;
if (a[1].fi == a[n].fi) {
int tmp = l - (1 + a[1].fi * (n - 1));
cout << (ncr(n + tmp, tmp) * gt[n]) % M << "\n";
return 0;
}
while((next_permutation(a + 1, a + n + 1))) {
int tmp = l - n;
For(i, 2, n) tmp -= max(a[i - 1].fi - 1, a[i].fi - 1);
ans = (ans + ncr(n + tmp, tmp)) % M;
}
cout << ans << "\n";
return 0;
}
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... |