//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int _i = 1; _i <= (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 1; _i <= (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 2e3 + 5;
const double eps = 1e-9;
int a[N], C[N][N], fac[N], dp[N][N];
int add(int x, int y) { return x+y < mod ? x+y : x+y-mod; }
int mul(int x, int y) { return x*1ll*y % mod; }
int main() {
fac[0] = C[0][0] = 1;
for (int i = 1; i < N; i++) {
fac[i] = mul(fac[i-1], i);
C[i][0] = 1;
for (int j = 1; j <= i; j++)
C[i][j] = add(C[i-1][j], C[i-1][j-1]);
}
int n; ni(n);
for (int i = 1; i <= n; i++) {
scanf("%d", a+i);
}
dp[1][1] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n+1; j++) {
if (dp[i][j] == 0)
continue;
for (int k = 0; k <= min(n, a[i] - i) - j + 1; k++) {
int val = mul(mul(dp[i][j], C[2*k][k]), mul(C[a[i]-i-j+1][k], fac[k]));
dp[i+1][j+k] = add(dp[i+1][j+k], mul(val, k > 0 ? 1 : j - i));
}
}
}
int ans = dp[n+1][n+1];
for (int i = 1; i <= n; i++)
ans = mul(ans, 500000004);
printf("%d\n", ans);
return 0;
}
Compilation message
ruins3.cpp: In function 'int main()':
ruins3.cpp:10:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ni(n) scanf("%d", &(n))
~~~~~^~~~~~~~~~~~
ruins3.cpp:49:10: note: in expansion of macro 'ni'
int n; ni(n);
^~
ruins3.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", a+i);
~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14208 KB |
Output is correct |
2 |
Correct |
13 ms |
14080 KB |
Output is correct |
3 |
Correct |
13 ms |
14208 KB |
Output is correct |
4 |
Correct |
14 ms |
14208 KB |
Output is correct |
5 |
Correct |
13 ms |
14208 KB |
Output is correct |
6 |
Correct |
14 ms |
14208 KB |
Output is correct |
7 |
Correct |
13 ms |
14208 KB |
Output is correct |
8 |
Correct |
15 ms |
14208 KB |
Output is correct |
9 |
Correct |
14 ms |
14208 KB |
Output is correct |
10 |
Correct |
13 ms |
14208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14208 KB |
Output is correct |
2 |
Correct |
13 ms |
14080 KB |
Output is correct |
3 |
Correct |
13 ms |
14208 KB |
Output is correct |
4 |
Correct |
14 ms |
14208 KB |
Output is correct |
5 |
Correct |
13 ms |
14208 KB |
Output is correct |
6 |
Correct |
14 ms |
14208 KB |
Output is correct |
7 |
Correct |
13 ms |
14208 KB |
Output is correct |
8 |
Correct |
15 ms |
14208 KB |
Output is correct |
9 |
Correct |
14 ms |
14208 KB |
Output is correct |
10 |
Correct |
13 ms |
14208 KB |
Output is correct |
11 |
Correct |
13 ms |
14464 KB |
Output is correct |
12 |
Correct |
14 ms |
14464 KB |
Output is correct |
13 |
Correct |
17 ms |
14592 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14208 KB |
Output is correct |
16 |
Correct |
15 ms |
14464 KB |
Output is correct |
17 |
Correct |
13 ms |
14208 KB |
Output is correct |
18 |
Correct |
13 ms |
14464 KB |
Output is correct |
19 |
Correct |
14 ms |
14464 KB |
Output is correct |
20 |
Correct |
14 ms |
14464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14208 KB |
Output is correct |
2 |
Correct |
13 ms |
14080 KB |
Output is correct |
3 |
Correct |
13 ms |
14208 KB |
Output is correct |
4 |
Correct |
14 ms |
14208 KB |
Output is correct |
5 |
Correct |
13 ms |
14208 KB |
Output is correct |
6 |
Correct |
14 ms |
14208 KB |
Output is correct |
7 |
Correct |
13 ms |
14208 KB |
Output is correct |
8 |
Correct |
15 ms |
14208 KB |
Output is correct |
9 |
Correct |
14 ms |
14208 KB |
Output is correct |
10 |
Correct |
13 ms |
14208 KB |
Output is correct |
11 |
Correct |
13 ms |
14464 KB |
Output is correct |
12 |
Correct |
14 ms |
14464 KB |
Output is correct |
13 |
Correct |
17 ms |
14592 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14208 KB |
Output is correct |
16 |
Correct |
15 ms |
14464 KB |
Output is correct |
17 |
Correct |
13 ms |
14208 KB |
Output is correct |
18 |
Correct |
13 ms |
14464 KB |
Output is correct |
19 |
Correct |
14 ms |
14464 KB |
Output is correct |
20 |
Correct |
14 ms |
14464 KB |
Output is correct |
21 |
Correct |
17 ms |
16640 KB |
Output is correct |
22 |
Correct |
16 ms |
16640 KB |
Output is correct |
23 |
Correct |
16 ms |
16640 KB |
Output is correct |
24 |
Correct |
18 ms |
16640 KB |
Output is correct |
25 |
Correct |
15 ms |
14208 KB |
Output is correct |
26 |
Correct |
14 ms |
14208 KB |
Output is correct |
27 |
Correct |
14 ms |
14208 KB |
Output is correct |
28 |
Correct |
15 ms |
16640 KB |
Output is correct |
29 |
Correct |
14 ms |
14208 KB |
Output is correct |
30 |
Correct |
321 ms |
17272 KB |
Output is correct |
31 |
Correct |
164 ms |
17144 KB |
Output is correct |
32 |
Correct |
239 ms |
17272 KB |
Output is correct |
33 |
Correct |
325 ms |
17272 KB |
Output is correct |
34 |
Correct |
162 ms |
17144 KB |
Output is correct |
35 |
Correct |
241 ms |
17272 KB |
Output is correct |
36 |
Correct |
305 ms |
17272 KB |
Output is correct |