Submission #221185

# Submission time Handle Problem Language Result Execution time Memory
221185 2020-04-09T16:20:02 Z DodgeBallMan Asceticism (JOI18_asceticism) C++14
100 / 100
103 ms 2040 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
long long mod = 1e9 + 7;
long long fac[N], inv[N], ans, n, k;
long long pow( long long base, long long p ) {
    long long ret = 1;
    for( ; p ; p >>= 1 ) {
        if( p & 1 ) ret = ( ret * base ) % mod;
        base = ( base * base ) % mod;
    }
    return ret;
}

long long ncr( long long a, long long b ) { return ( ( ( fac[a] * inv[b] ) % mod ) * inv[a-b] ) % mod; }

int main()
{
    fac[0] = inv[0] = 1;
    for( int i = 1 ; i < N ; i++ ) fac[i] = fac[i-1] * i % mod, inv[i] = pow( fac[i], mod-2 );
    scanf("%lld %lld",&n,&k);
    for( int i = 0 ; i <= k ; i++ ) {
        long long l = ncr( n, i ), r = pow( k - i, n );
        if( i < k ) r = ( r - pow( k - i - 1, n ) + mod ) % mod;
        l = l * r % mod;
        if( i & 1 ) ans = ( ans - l + mod ) % mod;
        else ans = ( ans + l ) % mod;
    }
    printf("%lld",ans);
    return 0;
}

Compilation message

asceticism.cpp: In function 'int main()':
asceticism.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1912 KB Output is correct
2 Correct 52 ms 1784 KB Output is correct
3 Correct 52 ms 1912 KB Output is correct
4 Correct 52 ms 1912 KB Output is correct
5 Correct 53 ms 1912 KB Output is correct
6 Correct 53 ms 1912 KB Output is correct
7 Correct 54 ms 1912 KB Output is correct
8 Correct 52 ms 1916 KB Output is correct
9 Correct 52 ms 1916 KB Output is correct
10 Correct 52 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1912 KB Output is correct
2 Correct 52 ms 1784 KB Output is correct
3 Correct 52 ms 1912 KB Output is correct
4 Correct 52 ms 1912 KB Output is correct
5 Correct 53 ms 1912 KB Output is correct
6 Correct 53 ms 1912 KB Output is correct
7 Correct 54 ms 1912 KB Output is correct
8 Correct 52 ms 1916 KB Output is correct
9 Correct 52 ms 1916 KB Output is correct
10 Correct 52 ms 1912 KB Output is correct
11 Correct 52 ms 1912 KB Output is correct
12 Correct 52 ms 1912 KB Output is correct
13 Correct 53 ms 1912 KB Output is correct
14 Correct 52 ms 1912 KB Output is correct
15 Correct 52 ms 1916 KB Output is correct
16 Correct 52 ms 1912 KB Output is correct
17 Correct 52 ms 1912 KB Output is correct
18 Correct 52 ms 1912 KB Output is correct
19 Correct 53 ms 2040 KB Output is correct
20 Correct 53 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1912 KB Output is correct
2 Correct 52 ms 1784 KB Output is correct
3 Correct 52 ms 1912 KB Output is correct
4 Correct 52 ms 1912 KB Output is correct
5 Correct 53 ms 1912 KB Output is correct
6 Correct 53 ms 1912 KB Output is correct
7 Correct 54 ms 1912 KB Output is correct
8 Correct 52 ms 1916 KB Output is correct
9 Correct 52 ms 1916 KB Output is correct
10 Correct 52 ms 1912 KB Output is correct
11 Correct 52 ms 1912 KB Output is correct
12 Correct 52 ms 1912 KB Output is correct
13 Correct 53 ms 1912 KB Output is correct
14 Correct 52 ms 1912 KB Output is correct
15 Correct 52 ms 1916 KB Output is correct
16 Correct 52 ms 1912 KB Output is correct
17 Correct 52 ms 1912 KB Output is correct
18 Correct 52 ms 1912 KB Output is correct
19 Correct 53 ms 2040 KB Output is correct
20 Correct 53 ms 1912 KB Output is correct
21 Correct 52 ms 1912 KB Output is correct
22 Correct 55 ms 1912 KB Output is correct
23 Correct 52 ms 1912 KB Output is correct
24 Correct 52 ms 1912 KB Output is correct
25 Correct 54 ms 2040 KB Output is correct
26 Correct 52 ms 1912 KB Output is correct
27 Correct 52 ms 1912 KB Output is correct
28 Correct 52 ms 1916 KB Output is correct
29 Correct 52 ms 1912 KB Output is correct
30 Correct 52 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1912 KB Output is correct
2 Correct 52 ms 1784 KB Output is correct
3 Correct 52 ms 1912 KB Output is correct
4 Correct 52 ms 1912 KB Output is correct
5 Correct 53 ms 1912 KB Output is correct
6 Correct 53 ms 1912 KB Output is correct
7 Correct 54 ms 1912 KB Output is correct
8 Correct 52 ms 1916 KB Output is correct
9 Correct 52 ms 1916 KB Output is correct
10 Correct 52 ms 1912 KB Output is correct
11 Correct 52 ms 1912 KB Output is correct
12 Correct 52 ms 1912 KB Output is correct
13 Correct 53 ms 1912 KB Output is correct
14 Correct 52 ms 1912 KB Output is correct
15 Correct 52 ms 1916 KB Output is correct
16 Correct 52 ms 1912 KB Output is correct
17 Correct 52 ms 1912 KB Output is correct
18 Correct 52 ms 1912 KB Output is correct
19 Correct 53 ms 2040 KB Output is correct
20 Correct 53 ms 1912 KB Output is correct
21 Correct 52 ms 1912 KB Output is correct
22 Correct 55 ms 1912 KB Output is correct
23 Correct 52 ms 1912 KB Output is correct
24 Correct 52 ms 1912 KB Output is correct
25 Correct 54 ms 2040 KB Output is correct
26 Correct 52 ms 1912 KB Output is correct
27 Correct 52 ms 1912 KB Output is correct
28 Correct 52 ms 1916 KB Output is correct
29 Correct 52 ms 1912 KB Output is correct
30 Correct 52 ms 1912 KB Output is correct
31 Correct 53 ms 1912 KB Output is correct
32 Correct 67 ms 1912 KB Output is correct
33 Correct 54 ms 1912 KB Output is correct
34 Correct 59 ms 1912 KB Output is correct
35 Correct 94 ms 1912 KB Output is correct
36 Correct 101 ms 1912 KB Output is correct
37 Correct 103 ms 1912 KB Output is correct
38 Correct 59 ms 1880 KB Output is correct
39 Correct 67 ms 1912 KB Output is correct
40 Correct 74 ms 1912 KB Output is correct