Submission #226206

# Submission time Handle Problem Language Result Execution time Memory
226206 2020-04-22T21:18:30 Z DS007 Asceticism (JOI18_asceticism) C++14
100 / 100
37 ms 1952 KB
#include <bits/stdc++.h>
 
#define long long long
 
using namespace std;
 
const int N = 1e5+5;
const int M = 1e9+7;
 
long modpow(long a, long b) {
    long ret = 1;
    for( ; b; b >>= 1) {
        if(b & 1) ret = ret * a % M;
        a = a * a % M;
    }
    return ret;
}
 
int n, k;
long fac[N], inv[N];
 
long ncr(int a, int b) {
    return fac[a] * inv[b] % M * inv[a - b] % M;
}
 
int main() {
    fac[0] = inv[0] = 1;
    for(int i = 1; i < N; i++) {
        fac[i] = fac[i-1] * i % M;
        inv[i] = modpow(fac[i], M - 2);
    }
 
    scanf("%d %d", &n, &k);
    long ans = 0;
    for(int i = 0; i <= k; i++) {
        long l = ncr(n, i), r = modpow(k - i, n);
        if(i < k) r = (r - modpow(k - i - 1, n) + M) % M;
        l = l * r % M;
        if(i & 1) ans = (ans - l + M) % M;
        else ans = (ans + l) % M;
    }
    printf("%lld\n", ans);
 
    return 0;
}

Compilation message

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