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;
int MOD = 1000007;
vector<int> seq;
vector<vector<int > > dp;
int main() {
int N, dpns, dps;cin>>N;
seq.assign(N, 0);
dp.assign(2, vector<int>(N+2, -1));
for (int i = N-1; i >= 0; i--) {
cin >> seq[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N+1; j++) {
dpns = j * dp[0][j] + dp[0][j+1];
dpns %= MOD;
dps = (dp[1][max(seq[i], j)]) + ((seq[i]-1)*dp[0][j]);
dps %= MOD;
dp[1][j] = dps;
dp[0][j] = dpns;
}
}
cout << dp[1][1] << 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... |