Submission #407054

# Submission time Handle Problem Language Result Execution time Memory
407054 2021-05-18T12:18:15 Z azberjibiou Asceticism (JOI18_asceticism) C++17
100 / 100
40 ms 1968 KB
#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define bp __builtin_popcount
#define fir first
#define sec second
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
int dx[4]={0, 1, 0, -1}, dy[4]={1, 0, -1 , 0};
const int mxN=100010;
const int mxM=350;
const int mxK=350;
const ll MOD=1000000007;
const ll INF=100000000000001;
int N, K;
ll fact[mxN], ifact[mxN];
ll ans;
ll mypow(ll a, ll b)
{
    if(b==0)    return 1;
    if(b==1)    return a%MOD;
    ll tmp=mypow(a, b/2);
    tmp=(tmp*tmp)%MOD;
    if(b%2) tmp=(a*tmp)%MOD;
    return tmp;
}
int main()
{
    gibon
    cin >> N >> K;  K--;
    fact[0]=1;  ifact[0]=1;
    for(int i=1;i<=N+1;i++)   fact[i]=(fact[i-1]*i)%MOD;
    for(int i=1;i<=N+1;i++)   ifact[i]=mypow(fact[i], MOD-2);
    for(int i=0;i<=K;i++)
    {
        ll res=fact[N+1];
        res*=ifact[i];  res%=MOD;
        res*=ifact[N+1-i];  res%=MOD;
        res*=mypow(K+1-i, N);   res%=MOD;
        if(i%2==0) ans=(ans+res)%MOD;
        else    ans=(ans+MOD-res)%MOD;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 26 ms 1848 KB Output is correct
32 Correct 26 ms 1824 KB Output is correct
33 Correct 27 ms 1848 KB Output is correct
34 Correct 28 ms 1968 KB Output is correct
35 Correct 38 ms 1868 KB Output is correct
36 Correct 39 ms 1872 KB Output is correct
37 Correct 40 ms 1792 KB Output is correct
38 Correct 7 ms 568 KB Output is correct
39 Correct 24 ms 1404 KB Output is correct
40 Correct 32 ms 1816 KB Output is correct