Submission #420777

# Submission time Handle Problem Language Result Execution time Memory
420777 2021-06-08T13:52:05 Z benedict0724 Asceticism (JOI18_asceticism) C++17
100 / 100
11 ms 1872 KB
#include <iostream>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;

ll fac[100002], invfac[100002], dp[100002];

ll pow(ll x, ll y)
{
    ll ans = 1;
    ll k = 0;
    while((1LL << k ) <= y)
    {
        if((1LL<<k) & y)
        {
            ans *= x;
            ans %= mod;
        }
        k++;
        x *= x;
        x %= mod;
    }
    return ans;
}

ll comb(ll n, ll k)
{
    ll ans = (fac[n] * invfac[k])%mod;
    ans = (ans * invfac[n-k])%mod;
    return ans;
}

int main()
{
    ll n, k; cin >> n >> k;
    fac[0] = 1;
    for(int i=1;i<=100001;i++) fac[i] = (fac[i-1] * i)%mod;
    invfac[100001] = pow(fac[100001], mod - 2);
    for(int i=100000;i>=0;i--) invfac[i] = (invfac[i+1] * (i+1))%mod;
    ll ans = 0;
    dp[1] = 1;
    for(ll i=0;i<=k;i++)
    {
        if(i%2 == 0) ans += (pow(k-i, n) * comb(n+1, i))%mod;
        else ans -= (pow(k-i, n) * comb(n+1, i))%mod;

        ans %= mod;
    }
    ans += mod;
    ans %= mod;
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 3 ms 1868 KB Output is correct
3 Correct 3 ms 1868 KB Output is correct
4 Correct 2 ms 1868 KB Output is correct
5 Correct 3 ms 1868 KB Output is correct
6 Correct 2 ms 1740 KB Output is correct
7 Correct 2 ms 1740 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 3 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 3 ms 1868 KB Output is correct
3 Correct 3 ms 1868 KB Output is correct
4 Correct 2 ms 1868 KB Output is correct
5 Correct 3 ms 1868 KB Output is correct
6 Correct 2 ms 1740 KB Output is correct
7 Correct 2 ms 1740 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 3 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 3 ms 1868 KB Output is correct
13 Correct 3 ms 1868 KB Output is correct
14 Correct 3 ms 1868 KB Output is correct
15 Correct 3 ms 1868 KB Output is correct
16 Correct 3 ms 1836 KB Output is correct
17 Correct 3 ms 1836 KB Output is correct
18 Correct 3 ms 1832 KB Output is correct
19 Correct 3 ms 1868 KB Output is correct
20 Correct 3 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 3 ms 1868 KB Output is correct
3 Correct 3 ms 1868 KB Output is correct
4 Correct 2 ms 1868 KB Output is correct
5 Correct 3 ms 1868 KB Output is correct
6 Correct 2 ms 1740 KB Output is correct
7 Correct 2 ms 1740 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 3 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 3 ms 1868 KB Output is correct
13 Correct 3 ms 1868 KB Output is correct
14 Correct 3 ms 1868 KB Output is correct
15 Correct 3 ms 1868 KB Output is correct
16 Correct 3 ms 1836 KB Output is correct
17 Correct 3 ms 1836 KB Output is correct
18 Correct 3 ms 1832 KB Output is correct
19 Correct 3 ms 1868 KB Output is correct
20 Correct 3 ms 1868 KB Output is correct
21 Correct 3 ms 1852 KB Output is correct
22 Correct 3 ms 1868 KB Output is correct
23 Correct 3 ms 1868 KB Output is correct
24 Correct 3 ms 1868 KB Output is correct
25 Correct 3 ms 1868 KB Output is correct
26 Correct 3 ms 1868 KB Output is correct
27 Correct 3 ms 1868 KB Output is correct
28 Correct 2 ms 1868 KB Output is correct
29 Correct 3 ms 1868 KB Output is correct
30 Correct 3 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 3 ms 1868 KB Output is correct
3 Correct 3 ms 1868 KB Output is correct
4 Correct 2 ms 1868 KB Output is correct
5 Correct 3 ms 1868 KB Output is correct
6 Correct 2 ms 1740 KB Output is correct
7 Correct 2 ms 1740 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 3 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 3 ms 1868 KB Output is correct
13 Correct 3 ms 1868 KB Output is correct
14 Correct 3 ms 1868 KB Output is correct
15 Correct 3 ms 1868 KB Output is correct
16 Correct 3 ms 1836 KB Output is correct
17 Correct 3 ms 1836 KB Output is correct
18 Correct 3 ms 1832 KB Output is correct
19 Correct 3 ms 1868 KB Output is correct
20 Correct 3 ms 1868 KB Output is correct
21 Correct 3 ms 1852 KB Output is correct
22 Correct 3 ms 1868 KB Output is correct
23 Correct 3 ms 1868 KB Output is correct
24 Correct 3 ms 1868 KB Output is correct
25 Correct 3 ms 1868 KB Output is correct
26 Correct 3 ms 1868 KB Output is correct
27 Correct 3 ms 1868 KB Output is correct
28 Correct 2 ms 1868 KB Output is correct
29 Correct 3 ms 1868 KB Output is correct
30 Correct 3 ms 1868 KB Output is correct
31 Correct 3 ms 1872 KB Output is correct
32 Correct 3 ms 1868 KB Output is correct
33 Correct 3 ms 1868 KB Output is correct
34 Correct 4 ms 1868 KB Output is correct
35 Correct 9 ms 1868 KB Output is correct
36 Correct 10 ms 1868 KB Output is correct
37 Correct 11 ms 1868 KB Output is correct
38 Correct 4 ms 1868 KB Output is correct
39 Correct 5 ms 1868 KB Output is correct
40 Correct 6 ms 1748 KB Output is correct