#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<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
vector<vector<int>> st(n + 1, vector<int>(n + 2, 0));
for (int i = 0; i < n + 2; i++) st[0][i] = 1;
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 i = 0; i <= n; i++) dp[i] = vector<int>(n + 1, 0);
for (int i = 0; i <= n; i++) st[i] = vector<int>(n + 2, 0);
for (int i = 0; i < n + 2; i++) st[0][i] = 1;
for (int j = n; j >= mmax + 1; j--)
{
for (int i = 1; i <= n; i++)
{
dp[i][j] = (dp[i - 1][j] + st[i - 1][j + 1]) * j;
st[i][j] = dp[i - 1][j] + st[i - 1][j + 1];
dp[i][j] %= MOD;
st[i][j] %= MOD;
}
}
int base = ip[i] - 1;
for (int j = n - i - 1; j >= 0; j--)
{
// cerr << i << " " << j << " " << base << "\n";
res += base*st[j][mmax + 1];
base *= mmax;
base %= MOD;
res %= MOD;
}
}
cout << (res + 1) << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
508 KB |
Output is correct |
2 |
Correct |
18 ms |
504 KB |
Output is correct |
3 |
Correct |
13 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1095 ms |
4344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
16120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
49 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
47 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
50 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |