#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e4 + 5;
const int mod = 1e6 + 7;
int add(int a,int b) {
a += b;
if(a >= mod)a -= mod;
return a;
}
int sub(int a,int b) {
a -= b;
if(a < 0) a += mod;
return a;
}
int mul(int a,int b) {
return (long long)a * b % mod;
}
int a[N], maxi[N];
int f[2][N];
int g[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
fill(f[0],f[0] + 1 + n,1); g[0] = 1;
for(int i = 0 ; i < n ; ++i) {
cin >> a[i];
maxi[i + 1] = max(maxi[i],a[i]);
}
for(int i = 1, p = 0 ; i < n ; ++i, p ^= 1) {
for(int j = 0 ; j <= n && j <= maxi[n - i - 1] + n - i ; ++j)
f[p ^ 1][j] = add(mul(f[p][j],j),f[p][j + 1]);
g[i] = f[p ^ 1][maxi[n - i - 1]];
}
int ans = 1;
for(int i = 0 ; i < n ; ++i) ans = add(ans,mul(a[i] - 1,g[n - i - 1]));
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
504 KB |
Output is correct |
2 |
Correct |
37 ms |
504 KB |
Output is correct |
3 |
Correct |
52 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
760 KB |
Output is correct |
2 |
Correct |
139 ms |
1016 KB |
Output is correct |
3 |
Correct |
209 ms |
760 KB |
Output is correct |