#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
ll C[1212][1212], K[666][1212][2], D[666], B[666];
bool A[1212];
ll n, s;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll i, j, l, c0, c1;
cin >> n;
for(i = C[0][0] = 1; i <= n; i ++){
for(j = C[i][0] = 1; j <= n; j ++){
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
}
K[0][0][0] = 1;
for(i = 1; i <= n; i ++){
c0 = c1 = 0;
for(j = 1; j <= n + n; j ++){
c0 = (c0 + K[i - 1][j - 1][0]) % mod;
if(j > i + i) K[i][j][0] = c0 * i % mod;
c1 = (c1 + K[i - 1][j - 1][1]) % mod;
if(j >= i + i - 1) K[i][j][1] = (c0 + c1 * (i - 1)) % mod;
}
B[i] = (K[i][i + i - 1][1] + K[i][i + i][1]) % mod;
}
for(i = 1; i <= n; i ++){
cin >> j; A[j] = 1;
}
D[0] = 1;
for(i = n + n, c0 = c1 = 0; i >= 1; i --){
if(A[i] == 1){
for(j = n; j >= 0; j --){
for(l = 0; l < j; l ++){
D[j] = (D[j] + D[l] * C[c1 - l][j - l - 1] % mod
* B[j - l]) % mod;
}
}
c1 ++;
}
else{
for(j = 0; j <= n; j ++){
D[j] = D[j] * (j - c0) % mod;
}
c0 ++;
}
}
s = D[n];
for(i = 1; i <= n; i ++){
s = s * (mod + 1 >> 1) % mod;
}
cout << s << "\n";
return 0;
}
Compilation message
ruins3.cpp: In function 'int main()':
ruins3.cpp:65:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
65 | s = s * (mod + 1 >> 1) % mod;
| ~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
896 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
2 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
896 KB |
Output is correct |
15 |
Correct |
2 ms |
896 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
896 KB |
Output is correct |
18 |
Correct |
1 ms |
896 KB |
Output is correct |
19 |
Correct |
1 ms |
896 KB |
Output is correct |
20 |
Correct |
2 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
0 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
896 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
2 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
896 KB |
Output is correct |
15 |
Correct |
2 ms |
896 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
896 KB |
Output is correct |
18 |
Correct |
1 ms |
896 KB |
Output is correct |
19 |
Correct |
1 ms |
896 KB |
Output is correct |
20 |
Correct |
2 ms |
896 KB |
Output is correct |
21 |
Correct |
702 ms |
13440 KB |
Output is correct |
22 |
Correct |
716 ms |
13464 KB |
Output is correct |
23 |
Correct |
749 ms |
13560 KB |
Output is correct |
24 |
Correct |
707 ms |
13560 KB |
Output is correct |
25 |
Correct |
710 ms |
13468 KB |
Output is correct |
26 |
Correct |
693 ms |
13560 KB |
Output is correct |
27 |
Correct |
694 ms |
13560 KB |
Output is correct |
28 |
Correct |
707 ms |
13440 KB |
Output is correct |
29 |
Correct |
695 ms |
13560 KB |
Output is correct |
30 |
Correct |
699 ms |
13560 KB |
Output is correct |
31 |
Correct |
691 ms |
13440 KB |
Output is correct |
32 |
Correct |
707 ms |
13468 KB |
Output is correct |
33 |
Correct |
692 ms |
13468 KB |
Output is correct |
34 |
Correct |
700 ms |
13688 KB |
Output is correct |
35 |
Correct |
753 ms |
13468 KB |
Output is correct |
36 |
Correct |
690 ms |
13468 KB |
Output is correct |