Submission #334550

# Submission time Handle Problem Language Result Execution time Memory
334550 2020-12-09T11:28:23 Z mehrdad_sohrabi Calvinball championship (CEOI15_teams) C++14
100 / 100
724 ms 620 KB
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
//#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=1e4+100;
int dp[2][N];
int a[N];
int mod=1e6+7;
int par[N];
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    for (int i=1;i<=n;i++){
        par[i]=max(par[i-1],a[i]);
    }
    for (int i=0;i<=n;i++){
        dp[0][i]=1;
    }
    ll ans=a[n];
    for (int i=1;i<n;i++){
        for (int j=1;j<=n;j++){
            dp[i%2][j]= (1ll * dp[(i-1)%2][j]*j+(ll)dp[(i-1)%2][j+1]) %(ll)mod;
           // dp[i%2][j]%=mod;
            //cout << i << " " << j << " " << dp[i][par] << endl;
        }
            ans+=1ll * dp[i%2][par[n-i-1]]*(a[n-i]-1)%(ll)mod;
    }
    cout << ans%mod;


}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 7 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 707 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 492 KB Output is correct
2 Correct 178 ms 492 KB Output is correct
3 Correct 177 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 722 ms 556 KB Output is correct
2 Correct 720 ms 620 KB Output is correct
3 Correct 724 ms 492 KB Output is correct