Submission #32738

# Submission time Handle Problem Language Result Execution time Memory
32738 2017-10-14T15:13:55 Z imaxblue Calvinball championship (CEOI15_teams) C++14
100 / 100
303 ms 2172 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()

int n, a[10005], b[10005], dp[2][10005], ans=1;
int main(){
    cin >> n;
    fox(l, n){
        cin >> a[l];
    }
    fox1(l, n) b[l]=max(b[l-1], a[l-1]);
    fox(l, n+1) dp[0][l]=1;
    foxr(l, n){
        memcpy(dp[1], dp[0], sizeof dp[0]);
        drain(dp[0]);
        fox(l2, n){
            dp[0][l2]=(1LL*l2*dp[1][l2]+dp[1][l2+1])%MN;
        }
        ans=(1LL*dp[1][b[l]]*(a[l]-1)+ans)%MN;
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
4 Correct 0 ms 2172 KB Output is correct
5 Correct 0 ms 2172 KB Output is correct
6 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2172 KB Output is correct
2 Correct 0 ms 2172 KB Output is correct
3 Correct 0 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2172 KB Output is correct
2 Correct 3 ms 2172 KB Output is correct
3 Correct 3 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2172 KB Output is correct
2 Correct 6 ms 2172 KB Output is correct
3 Correct 9 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 299 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2172 KB Output is correct
2 Correct 89 ms 2172 KB Output is correct
3 Correct 89 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 303 ms 2172 KB Output is correct
2 Correct 299 ms 2172 KB Output is correct
3 Correct 273 ms 2172 KB Output is correct