#include <iostream>
#include <vector>
#include <algorithm>
#define int int64_t
#define MOD (int)(1e6+7)
using namespace std;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> ip(n);
for (int i = 0; i < n; i++)
{
cin >> ip[i];
}
vector<int> dp(n + 1);
vector<int> st(n + 1);
st[0] = 1;
vector<int> oldst;
vector<int> olddp;
int last = n;
int res = 0;
for (int i = n - 1; i >= 0; i--)
{
int mmax = 0;
for (int j = 0; j < i; j++) mmax = max(mmax, ip[j]);
for (int j = last; j >= mmax + 1; j--)
{
swap(dp, olddp);
swap(st, oldst);
dp = vector<int>(n + 1, 0);
st = vector<int>(n + 1, 0);
for (int i = 1; i <= n; i++)
{
dp[i] = (dp[i - 1] + oldst[i - 1]) * j;
st[i] = dp[i - 1] + oldst[i - 1];
dp[i] %= MOD;
st[i] %= MOD;
}
}
last = mmax;
int base = ip[i] - 1;
for (int j = n - i - 1; j >= 0; j--)
{
// cerr << i << " " << j << " " << base << "\n";
res += base*st[j];
base *= mmax;
base %= MOD;
res %= MOD;
}
}
cout << (res + 1) << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
760 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
401 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |