# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892361 | 2023-12-25T09:12:54 Z | tradz | Magneti (COCI21_magneti) | C++14 | 1000 ms | 4696 KB |
#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 + 1 << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4440 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 1 ms | 4444 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 4444 KB | Output is correct |
6 | Correct | 1 ms | 4444 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4444 KB | Output is correct |
9 | Correct | 1 ms | 4444 KB | Output is correct |
10 | Correct | 1 ms | 4444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 63 ms | 4696 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1067 ms | 4444 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4440 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 1 ms | 4444 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 4444 KB | Output is correct |
6 | Correct | 1 ms | 4444 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4444 KB | Output is correct |
9 | Correct | 1 ms | 4444 KB | Output is correct |
10 | Correct | 1 ms | 4444 KB | Output is correct |
11 | Incorrect | 63 ms | 4696 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |