Submission #330867

# Submission time Handle Problem Language Result Execution time Memory
330867 2020-11-26T19:18:09 Z Sho10 Calvinball championship (CEOI15_teams) C++14
100 / 100
264 ms 748 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[10005],pref[10005],dp[10005],dp2[10005];
int32_t main(){
CODE_START;
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
    pref[i]=max(pref[i-1],a[i]);
}
ll ans=1;
for(ll i=n;i>=1;i--)
{
    if(i==n){
        for(ll j=0;j<=n;j++)
        {
            dp[j]=1;
        }
    }else {
    for(ll j=0;j<i;j++)
    {
dp[j]=((j*dp2[j])%mod+dp2[j+1])%mod;
    }

}
ans=(ans+((a[i]-1)*dp[pref[i-1]]%mod)%mod)%mod;
swap(dp,dp2);
}
cout<<ans<<endl;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 492 KB Output is correct
2 Correct 9 ms 492 KB Output is correct
3 Correct 10 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 748 KB Output is correct
2 Correct 76 ms 620 KB Output is correct
3 Correct 77 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 748 KB Output is correct
2 Correct 264 ms 748 KB Output is correct
3 Correct 250 ms 748 KB Output is correct