#include <stdio.h>
#define N 50
#define M 10000
#define MD 1000000007
int max(int a, int b) { return a > b ? a : b; }
int vv[M + 1], ff[M + 1], gg[M + 1];
void init() {
int i;
ff[0] = gg[0] = 1;
for (i = 1; i <= M; i++) {
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
ff[i] = (long long) ff[i - 1] * i % MD;
gg[i] = (long long) gg[i - 1] * vv[i] % MD;
}
}
int choose(int n, int k) {
return k < 0 || k > n ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}
int pp[N], rr[N], n, l, ans; char used[N];
void branch(int i) {
if (i == n) {
int d = 0;
for (i = 1; i < n; i++)
d += max(rr[pp[i]], rr[pp[i - 1]]) - 1;
ans = (ans + (long long) choose(l - d, n)) % MD;
return;
}
for (pp[i] = 0; pp[i] < n; pp[i]++)
if (!used[pp[i]])
used[pp[i]] = 1, branch(i + 1), used[pp[i]] = 0;
}
int main() {
int i;
init();
scanf("%d%d", &n, &l);
for (i = 0; i < n; i++)
scanf("%d", &rr[i]);
if (n <= 10) {
branch(0);
printf("%d\n", ans);
} else
printf("%lld\n", (long long) choose(l - (rr[0] - 1) * (n - 1), n) * ff[n] % MD);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:46:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d%d", &n, &l);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:48:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d", &rr[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
392 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
302 ms |
380 KB |
Output is correct |
2 |
Correct |
0 ms |
392 KB |
Output is correct |
3 |
Correct |
268 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
251 ms |
372 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
244 ms |
372 KB |
Output is correct |
8 |
Correct |
251 ms |
368 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
392 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
302 ms |
380 KB |
Output is correct |
12 |
Correct |
0 ms |
392 KB |
Output is correct |
13 |
Correct |
268 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
251 ms |
372 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
244 ms |
372 KB |
Output is correct |
18 |
Correct |
251 ms |
368 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |