This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F
const int B = 1e2 + 5;
const int MXN = 1e4 + 5;
const int mod = 1e6 + 7;
int dp[B][MXN];
int bl[B][MXN];
int cur[MXN], nw[MXN];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, res = 0;
cin >> n;
int a[n + 1], p[n + 1];
p[0] = 0;
for (int i = 1; i <= n; i++) cin >> a[i], p[i] = max(p[i - 1], a[i]);
fill(cur + 1, cur + n + 1, 1);
for (int i = n - 1; i >= 1; i--)
{
res = (res + (((a[i + 1] - 1) * cur[p[i]]) % mod)) % mod;
for (int j = 1; j <= n; j++) nw[j] = cur[j + 1] + (cur[j] * j) % mod;
for (int j = 1; j <= n; j++) cur[j] = nw[j];
}
cout << (res + 1) % mod << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |