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
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int mod = 1e6 + 7;
void solve() {
int n;
cin >> n;
vector<int> v(1 + n, 0);
for(int i = 1; i <= n; i++) {
cin >> v[i];
}
vector<int> dp(1 + n, 0);
for(int i = 1; i <= n; i++) {
dp[i] = 1;
}
int ans = 0;
for(int i = n; i >= 1; i--) {
for(int j = 1; j <= v[i] - 1; j++) {
ans += dp[j];
ans %= mod;
}
for(int j = 1; j <= i - 1; j++) {
dp[j] = dp[j] * j + dp[j + 1];
dp[j] %= mod;
}
}
ans++;
ans %= mod;
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
# | 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... |