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
int mod = 1e9 + 7;
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
for (int &x : a)
cin >> x;
vector<int> pref = a;
for (int i = 1; i < n; i++)
{
pref[i] = max(pref[i - 1], pref[i]);
}
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 1));
int count = 1;
for (int i = n - 1; i >= 1; i--)
{
for (int max_here = 1; max_here <= i; max_here++)
{
dp[i][max_here] = ((dp[i + 1][max_here] * max_here) % mod + dp[i + 1][max_here + 1]) % mod;
}
count += ((dp[i + 1][pref[i - 1]]) * (a[i] - 1)) % mod;
count %= mod;
}
cout << count;
}
# | 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... |