#include <bits/stdc++.h>
using namespace std;
#define MODVAL 1000007
typedef long long ll;
typedef vector<int> vi;
int n, m[10010];
ll dp[200020];
vi a;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a = {1};
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
a.push_back(tmp);
}
n++;
reverse(a.begin(), a.end());
int mx = 1;
for (int i = n - 1; i >= 0; i--) {
if (a[i] > mx) mx = a[i];
m[i] = mx;
}
fill(dp, dp + 2 * n + 10, 1);
ll ans = 1;
for (int i = 0; i < n - 1; i++) {
if (i) for (int j = 0; j < 2 * n + 5; j++) {
dp[j] *= j;
dp[j] %= MODVAL;
dp[j] += dp[j + 1];
dp[j] %= MODVAL;
}
ans += ((a[i] - 1) * dp[m[i + 1]]) % MODVAL;
ans %= MODVAL;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
328 KB |
Output is correct |
2 |
Correct |
8 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
699 ms |
648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
460 KB |
Output is correct |
2 |
Correct |
178 ms |
460 KB |
Output is correct |
3 |
Correct |
182 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
716 ms |
640 KB |
Output is correct |
2 |
Correct |
716 ms |
636 KB |
Output is correct |
3 |
Correct |
724 ms |
660 KB |
Output is correct |