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