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
const int M = 1e6+7;
int32_t main() {
int N;
cin >> N;
int a[N], res{1};
for(int &i : a) cin >> i, --i;
vector<int> dp(N+1, 1);
for(int i = N; i--; ) {
res += a[i] * dp[i ? *max_element(a, a+i) + 1 : 0];
for(int j = 0; j <= N; ++j)
dp[j] = ((j + 1 < N ? dp[j + 1] : 0LL) + j * dp[j]) % M;
}
cout << (res % M);
}
# | 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... |