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];
for(int &i : a) cin >> i, --i;
int b[N] {a[0]}, res = 1;
for(int i = 1; i < N; ++i)
b[i] = max(b[i-1], a[i]);
vector<int> cur(N+1, 1), dp(N+1);
for(int i = N; i--; ) {
swap(cur, dp);
for(int j = 0; j <= N; ++j)
cur[j] = ((j + 1 < N ? dp[j + 1] : 0LL) + j * dp[j]) % M;
res += a[i] * dp[i ? b[i-1] + 1 : 0];
}
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... |