#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int ll
const int MAXN = 1005, M2 = 2005;
const ll md = 1e9+7;
ll n, a[MAXN], pt = 0;
ll dp[MAXN][M2], ans = 0;
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
for(int i = 1; i < M2; i++) dp[1][i] = i+1, dp[0][i] = 1ll;
for(ll i = 2; i < MAXN; i++)
for(ll j = 1; j < M2; j++){
dp[i][j] = (j*dp[i-1][j])%md;
if(j+1 < M2) dp[i][j] = (dp[i][j]+dp[i-1][j+1])%md;
}
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
pt = 1;
for(int i = 0; i < n; i++){
if(a[i]==1) continue;
ll tmp = (ll)a[i]-1ll;
tmp = (tmp*dp[n-i-1][pt])%md;
ans = (ans+tmp)%md;
if(a[i]==pt+1) pt++;
}
cout << (ans+1)%md << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
16028 KB |
Output is correct |
2 |
Correct |
18 ms |
15988 KB |
Output is correct |
3 |
Correct |
15 ms |
16096 KB |
Output is correct |
4 |
Correct |
15 ms |
16008 KB |
Output is correct |
5 |
Correct |
15 ms |
16076 KB |
Output is correct |
6 |
Correct |
16 ms |
16012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16088 KB |
Output is correct |
2 |
Correct |
15 ms |
16076 KB |
Output is correct |
3 |
Correct |
15 ms |
16076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
15976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
16096 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
16084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
16088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
16028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
16092 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
16056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
16100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |