Submission #859001

# Submission time Handle Problem Language Result Execution time Memory
859001 2023-10-09T14:16:16 Z Tenis0206 Calvinball championship (CEOI15_teams) C++11
20 / 100
1000 ms 604 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 1e4;
const int Mod = 1e9 + 7;

int n;
int v[nmax + 5];

int fact[nmax + 5], invfact[nmax + 5];

int dp[nmax + 5];

int lgput(int a, int b)
{
    int p = 1;
    while(b)
    {
        if(b % 2 == 0)
        {
            b/=2;
            a = 1LL * a * a % Mod;
        }
        else
        {
            --b;
            p = 1LL * p * a % Mod;
        }
    }
    return p;
}

int invmod(int x)
{
    return lgput(x,Mod-2);
}

int comb(int n, int k)
{
    return 1LL * fact[n] * invfact[k] % Mod * invfact[n - k] % Mod;
}

void precalc()
{
    fact[0] = 1;
    for(int i=1;i<=nmax;i++)
    {
        fact[i] = 1LL * fact[i - 1] * i % Mod;
    }
    invfact[nmax] = invmod(fact[nmax]);
    for(int i=nmax-1;i>=0;i--)
    {
        invfact[i] = 1LL * invfact[i + 1] * (i + 1) % Mod;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef home
    freopen("nr.in","r",stdin);
    freopen("nr.out","w",stdout);
    #endif // home
    cin>>n;
    precalc();
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    dp[0] = 1;
    for(int i=0;i<=n;i++)
    {
        for(int nr=1;i+nr<=n;nr++)
        {
            dp[i + nr] += 1LL * dp[i] * comb(i + nr - 1, nr - 1) % Mod;
            dp[i + nr] %= Mod;
        }
    }
    int Max = 0;
    long long rez = 0;
    for(int i=1;i<=n;i++)
    {
        if(v[i]==1)
        {
            Max = max(Max, v[i]);
            continue;
        }
        for(int nr=0;i+nr<=n;nr++)
        {
            rez += 1LL * dp[nr] * comb(n - i, nr) % Mod * lgput(Max, n - i - nr) % Mod * (v[i] - 1) % Mod;
            rez %= Mod;
        }
        Max = max(Max, v[i]);
    }
    rez = (rez + 1) % Mod;
    cout<<rez<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1048 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 796 ms 556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1041 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -