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;
const int MOD = 1000007;
int main(){
int n;
cin >> n;
int dp[2][1 + n];
int cur = n % 2;
int a[1 + n];
int prefMax[1 + n];
prefMax[0] = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
prefMax[i] = max(prefMax[i - 1], a[i]);
dp[cur][i] = 1;
}
int ans = 1;
for(int i = n - 1; i > 0; i--, cur ^= 1){
ans = (ans + dp[cur][prefMax[i]] * (a[i + 1] - 1)) % MOD;
for(int j = 1; j <= i; j++){
dp[!cur][j] = (dp[cur][j] * j + dp[cur][j + 1]) % MOD;
}
}
cout << ans << "\n";
}
# | 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... |