#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e4+4, M = 1e6+7;
int n, a[maxn];
int dp[2][maxn];
int k[maxn];
void madd(int& a, int b) {
a = (a+b) % M;
}
int mult(int a, int b) {
return (1LL*a*b) % M;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
k[i] = max(k[i-1],a[i-1]);
}
for (int i = 1; i <= n+1; i++) {
dp[0][i] = 1;
}
int ans = 0;
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
dp[1][j] = (mult(j,dp[0][j]) + dp[0][j+1]) % M;
}
if (k[i] < a[i]) {
madd(ans,mult(k[i],dp[0][k[i]]));
}
else {
madd(ans,mult(a[i]-1,dp[0][k[i]]));
}
for (int j = 1; j <= n; j++) {
dp[0][j] = dp[1][j];
}
}
cout << ((ans+1)%M) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
239 ms |
532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
472 KB |
Output is correct |
2 |
Correct |
55 ms |
492 KB |
Output is correct |
3 |
Correct |
55 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
536 KB |
Output is correct |
2 |
Correct |
215 ms |
512 KB |
Output is correct |
3 |
Correct |
216 ms |
512 KB |
Output is correct |