Submission #159780

# Submission time Handle Problem Language Result Execution time Memory
159780 2019-10-24T14:47:01 Z combi1k1 Asceticism (JOI18_asceticism) C++14
100 / 100
14 ms 1272 KB
#include<bits/stdc++.h>

using namespace std;

const int   N   = 1e5 + 5;
const int   mod = 1e9 + 7;

int add(int a,int b)    {
    a += b;
    if(a >= mod)a -= mod;
    return  a;
}
int sub(int a,int b)    {
    a -= b;
    if(a <  0)  a += mod;
    return  a;
}
int mul(int a,int b)    {
    return  1ll * a * b % mod;
}
int Pow(int a,int b)    {
    int ans = 1;
    for(; b ; b >>= 1, a = mul(a,a))    if (b & 1)
        ans = mul(ans, a);

    return  ans;
}

int Fac[N];
int Inv[N];

int Ckn(int n,int k)    {
    if (n < k)  return  0;
    if (k < 0)  return  0;

    return  mul(Fac[n],mul(Inv[k],Inv[n - k]));
}

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    int k;  cin >> k;

    Fac[0] = Inv[0] = 1;

    for(int i = 1 ; i < N ; ++i)    Fac[i] = mul(Fac[i - 1],i); Inv[N - 1] = Pow(Fac[N - 1],mod - 2);
    for(int i = N - 2 ; i ; --i)    Inv[i] = mul(Inv[i + 1],i + 1);

    int ans = 0;

    for(int i = 0 ; i < k ; ++i)   {
        int cur = mul(Ckn(n + 1,i),Pow(k - i,n));
        if (i & 1)  ans = sub(ans,cur);
        else        ans = add(ans,cur);
    }

    cout << ans << endl;
}

Compilation message

asceticism.cpp: In function 'int main()':
asceticism.cpp:48:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(int i = 1 ; i < N ; ++i)    Fac[i] = mul(Fac[i - 1],i); Inv[N - 1] = Pow(Fac[N - 1],mod - 2);
     ^~~
asceticism.cpp:48:65: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for(int i = 1 ; i < N ; ++i)    Fac[i] = mul(Fac[i - 1],i); Inv[N - 1] = Pow(Fac[N - 1],mod - 2);
                                                                 ^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 4 ms 1144 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 4 ms 1144 KB Output is correct
7 Correct 4 ms 1016 KB Output is correct
8 Correct 4 ms 1144 KB Output is correct
9 Correct 4 ms 1144 KB Output is correct
10 Correct 4 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 4 ms 1144 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 4 ms 1144 KB Output is correct
7 Correct 4 ms 1016 KB Output is correct
8 Correct 4 ms 1144 KB Output is correct
9 Correct 4 ms 1144 KB Output is correct
10 Correct 4 ms 1144 KB Output is correct
11 Correct 4 ms 1144 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 4 ms 1144 KB Output is correct
16 Correct 4 ms 1144 KB Output is correct
17 Correct 4 ms 1144 KB Output is correct
18 Correct 4 ms 1144 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 4 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 4 ms 1144 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 4 ms 1144 KB Output is correct
7 Correct 4 ms 1016 KB Output is correct
8 Correct 4 ms 1144 KB Output is correct
9 Correct 4 ms 1144 KB Output is correct
10 Correct 4 ms 1144 KB Output is correct
11 Correct 4 ms 1144 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 4 ms 1144 KB Output is correct
16 Correct 4 ms 1144 KB Output is correct
17 Correct 4 ms 1144 KB Output is correct
18 Correct 4 ms 1144 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 4 ms 1144 KB Output is correct
21 Correct 4 ms 1056 KB Output is correct
22 Correct 4 ms 1144 KB Output is correct
23 Correct 4 ms 1144 KB Output is correct
24 Correct 4 ms 1144 KB Output is correct
25 Correct 4 ms 1272 KB Output is correct
26 Correct 4 ms 1144 KB Output is correct
27 Correct 4 ms 1144 KB Output is correct
28 Correct 4 ms 1144 KB Output is correct
29 Correct 4 ms 1144 KB Output is correct
30 Correct 4 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 4 ms 1144 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 4 ms 1144 KB Output is correct
7 Correct 4 ms 1016 KB Output is correct
8 Correct 4 ms 1144 KB Output is correct
9 Correct 4 ms 1144 KB Output is correct
10 Correct 4 ms 1144 KB Output is correct
11 Correct 4 ms 1144 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 4 ms 1144 KB Output is correct
16 Correct 4 ms 1144 KB Output is correct
17 Correct 4 ms 1144 KB Output is correct
18 Correct 4 ms 1144 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 4 ms 1144 KB Output is correct
21 Correct 4 ms 1056 KB Output is correct
22 Correct 4 ms 1144 KB Output is correct
23 Correct 4 ms 1144 KB Output is correct
24 Correct 4 ms 1144 KB Output is correct
25 Correct 4 ms 1272 KB Output is correct
26 Correct 4 ms 1144 KB Output is correct
27 Correct 4 ms 1144 KB Output is correct
28 Correct 4 ms 1144 KB Output is correct
29 Correct 4 ms 1144 KB Output is correct
30 Correct 4 ms 1144 KB Output is correct
31 Correct 4 ms 1144 KB Output is correct
32 Correct 4 ms 1144 KB Output is correct
33 Correct 5 ms 1148 KB Output is correct
34 Correct 5 ms 1144 KB Output is correct
35 Correct 12 ms 1144 KB Output is correct
36 Correct 13 ms 1144 KB Output is correct
37 Correct 14 ms 1144 KB Output is correct
38 Correct 5 ms 1144 KB Output is correct
39 Correct 7 ms 1144 KB Output is correct
40 Correct 8 ms 1144 KB Output is correct