# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
892363 | 2023-12-25T09:14:18 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; } do { 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; } while(next_permutation(a + 1, a + n + 1)); cout << ans << "\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 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 | 4440 KB | Output is correct |
5 | Correct | 1 ms | 4444 KB | Output is correct |
6 | Correct | 1 ms | 4652 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 4696 KB | Output is correct |
2 | Correct | 1 ms | 4440 KB | Output is correct |
3 | Correct | 63 ms | 4564 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 43 ms | 4444 KB | Output is correct |
6 | Correct | 1 ms | 4444 KB | Output is correct |
7 | Correct | 44 ms | 4544 KB | Output is correct |
8 | Correct | 39 ms | 4444 KB | Output is correct |
9 | Correct | 1 ms | 4448 KB | Output is correct |
10 | Correct | 1 ms | 4444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1079 ms | 4444 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 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 | 4440 KB | Output is correct |
5 | Correct | 1 ms | 4444 KB | Output is correct |
6 | Correct | 1 ms | 4652 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 | Correct | 62 ms | 4696 KB | Output is correct |
12 | Correct | 1 ms | 4440 KB | Output is correct |
13 | Correct | 63 ms | 4564 KB | Output is correct |
14 | Correct | 1 ms | 4444 KB | Output is correct |
15 | Correct | 43 ms | 4444 KB | Output is correct |
16 | Correct | 1 ms | 4444 KB | Output is correct |
17 | Correct | 44 ms | 4544 KB | Output is correct |
18 | Correct | 39 ms | 4444 KB | Output is correct |
19 | Correct | 1 ms | 4448 KB | Output is correct |
20 | Correct | 1 ms | 4444 KB | Output is correct |
21 | Execution timed out | 1079 ms | 4444 KB | Time limit exceeded |
22 | Halted | 0 ms | 0 KB | - |