This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// Created by 42kangaroo on 30/08/2024.
//
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
constexpr ll mod = 1e6 + 7;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> nuD(n);
int act = 1;
for (int i = 0; i < n; ++i) {
if (a[i] > act) act++;
nuD[i] = act;
}
vector<ll> dp(n + 1, 1), dpN(n + 1, 0);
ll res = 1;
for (int i = n - 1; i >= 0; --i) {
res += (dp[nuD[i] - 1] * (a[i] - 1))%mod;
res %= mod;
for (int j = 0; j < n; ++j) {
dpN[j] = (dp[j] * j)%mod + dp[j + 1];
dpN[j] %= mod;
}
swap(dp, dpN);
}
cout << res;
}
# | 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... |