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 ll long long
#define pb push_back
const int maxn = 1e4 + 20;
const int mod = 1e6 + 7;
int dp[2][maxn] , a[maxn] , mx[maxn];
inline void mkay(int &a)
{
if(a >= mod)
a -= mod;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i] , mx[i] = max(mx[i - 1] , a[i]);
for(int i = 0; i <= n; i++)
dp[0][i] = 1;
int res = 1;
for(int i = 0; i < n; i++)
{
int x = (i&1);
if(i)
for(int j = 0; j <= n; j++)
dp[x][j] = (1LL * dp[x ^ 1][j] * j + dp[x ^ 1][j + 1]) % mod;
int tmp = 1LL * (a[n - i] - 1) * dp[x][mx[n - i - 1]] % mod;
mkay(res += tmp);
}
cout << res << endl;
}
# | 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... |