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 <iostream>
using namespace std;
const int mod = 1e6 + 7;
const int nmax = 1e5 + 2;
int dp[2][nmax];
int a[nmax];
int main()
{
int n; cin >> n;
int maxx = 1;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
dp[i % 2][maxx] += a[i] - 1;
for (int k = maxx + 1; k < a[i]; k++)
{
dp[i % 2][k]++;
}
for (int k = n; k > 0; k--)
{
dp[i % 2][k] += dp[(i-1) % 2][k-1] + dp[(i-1) % 2][k] * k;
// cout << i << ' ' << k << ' ' << dp[i % 2][k] << '\n';
dp[i%2][k] %= mod;
}
maxx = max(maxx , a[i]);
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
ans += dp[n % 2][i];
ans %= mod;
}
cout << (ans + 1) % mod << '\n';
return 0;
}
# | 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... |