This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//https://oj.uz/problem/view/CEOI15_teams
#include<bits/stdc++.h>
const int N = 1e4 + 5;
const int mod = 1e6 + 7;
using namespace std;
int n, a[N], f[N], g[N], cur[N], ans;
void add(int&a, int b){
a += b; if (a >= mod) a -= mod; if (a < 0) a += mod;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
cur[i] = max(cur[i-1], a[i]);
}
for (int i = 0; i <= n; i++) f[i] = 1;
for (int i = n; i >= 1; i--){
add(ans, 1LL * f[cur[i-1]] * (a[i]-1) % mod);
for (int j = 0; j <= n; j++) g[j] = (1LL * f[j] * j + f[j+1]) % mod;
for (int j = 0; j <= n; j++) f[j] = g[j];
}
add(ans, 1);
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... |