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
const int MOD = 1000007;
signed main(){
int n; cin >> n;
int a[n], p[n];
for(int i = 0; i < n; i ++)
cin >> a[i];
p[0] = 0;
for(int i = 1; i < n; i ++)
p[i] = max(p[i-1], a[i-1]);
int bef[n+1], cur[n+1];
for(int i = 0; i < n; i ++)
bef[i] = 1;
int ans = 1;
for(int i = n-1; i >= 0; i --){
ans = (ans + (a[i]-1)*bef[p[i]]) % MOD;
for(int k = 0; k < i; k ++)
cur[k] = (k*bef[k] + bef[k+1]) % MOD;
for(int k = 0; k <= n; k ++)
swap(bef[k], cur[k]);
}
cout << ans;
}
# | 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... |