#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#include <deque>
#include <climits>
#define scanf scanf_s
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007, N = 2010.;
ll n, a[N], ans = 0,dp[N][N],dp2[N][N];
ll cal(ll lgt, ll knd) {
return dp[lgt][knd] + dp2[lgt][knd + 1];
}
int main() {
for (int i = 1; i < N; i++) { dp[1][i] = i; dp2[1][i] = 1; dp[0][i] = 1; }
for (int i = 2; i < N; i++) {
for (int j = 1; j < N - 1; j++) {
dp[i][j] = (dp[i - 1][j] * j + dp2[i - 1][j + 1]) % MOD;
dp2[i][j] = (dp2[i - 1][j] * j + dp2[i - 1][j + 1]) % MOD;
}
}
cin >> n;
for (int i = 1; i <= n; i++)cin >> a[i];
ll knd = 0;
for (int i = 1; i <= n; i++) {
ll v1 = (a[i] - 1) * cal(n - i, knd);
v1 %= MOD;
ans = (ans + v1) % MOD;
knd = max(knd, a[i]);
}
ans = (ans + 1) % MOD;
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
63480 KB |
Output is correct |
2 |
Correct |
71 ms |
63480 KB |
Output is correct |
3 |
Correct |
66 ms |
63480 KB |
Output is correct |
4 |
Correct |
57 ms |
63548 KB |
Output is correct |
5 |
Correct |
66 ms |
63608 KB |
Output is correct |
6 |
Correct |
75 ms |
63480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
63496 KB |
Output is correct |
2 |
Incorrect |
76 ms |
63608 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
63564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
63552 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
63556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
63540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
63608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
63580 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
63580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
63596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |