Submission #202299

# Submission time Handle Problem Language Result Execution time Memory
202299 2020-02-15T07:43:43 Z PeppaPig Asceticism (JOI18_asceticism) C++14
100 / 100
39 ms 2040 KB
//Each exam choose a group represents its day, then choose i exam as day change but the next exam id is greater

#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:35: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 22 ms 1888 KB Output is correct
2 Correct 21 ms 1912 KB Output is correct
3 Correct 21 ms 1824 KB Output is correct
4 Correct 22 ms 1912 KB Output is correct
5 Correct 22 ms 1912 KB Output is correct
6 Correct 22 ms 1912 KB Output is correct
7 Correct 21 ms 1912 KB Output is correct
8 Correct 23 ms 1924 KB Output is correct
9 Correct 21 ms 1912 KB Output is correct
10 Correct 22 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1888 KB Output is correct
2 Correct 21 ms 1912 KB Output is correct
3 Correct 21 ms 1824 KB Output is correct
4 Correct 22 ms 1912 KB Output is correct
5 Correct 22 ms 1912 KB Output is correct
6 Correct 22 ms 1912 KB Output is correct
7 Correct 21 ms 1912 KB Output is correct
8 Correct 23 ms 1924 KB Output is correct
9 Correct 21 ms 1912 KB Output is correct
10 Correct 22 ms 1912 KB Output is correct
11 Correct 22 ms 1912 KB Output is correct
12 Correct 23 ms 1912 KB Output is correct
13 Correct 23 ms 1912 KB Output is correct
14 Correct 21 ms 1912 KB Output is correct
15 Correct 22 ms 1912 KB Output is correct
16 Correct 21 ms 1912 KB Output is correct
17 Correct 21 ms 1912 KB Output is correct
18 Correct 22 ms 1912 KB Output is correct
19 Correct 21 ms 1912 KB Output is correct
20 Correct 21 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1888 KB Output is correct
2 Correct 21 ms 1912 KB Output is correct
3 Correct 21 ms 1824 KB Output is correct
4 Correct 22 ms 1912 KB Output is correct
5 Correct 22 ms 1912 KB Output is correct
6 Correct 22 ms 1912 KB Output is correct
7 Correct 21 ms 1912 KB Output is correct
8 Correct 23 ms 1924 KB Output is correct
9 Correct 21 ms 1912 KB Output is correct
10 Correct 22 ms 1912 KB Output is correct
11 Correct 22 ms 1912 KB Output is correct
12 Correct 23 ms 1912 KB Output is correct
13 Correct 23 ms 1912 KB Output is correct
14 Correct 21 ms 1912 KB Output is correct
15 Correct 22 ms 1912 KB Output is correct
16 Correct 21 ms 1912 KB Output is correct
17 Correct 21 ms 1912 KB Output is correct
18 Correct 22 ms 1912 KB Output is correct
19 Correct 21 ms 1912 KB Output is correct
20 Correct 21 ms 1912 KB Output is correct
21 Correct 21 ms 1912 KB Output is correct
22 Correct 22 ms 1932 KB Output is correct
23 Correct 21 ms 1924 KB Output is correct
24 Correct 22 ms 1912 KB Output is correct
25 Correct 22 ms 1912 KB Output is correct
26 Correct 22 ms 1912 KB Output is correct
27 Correct 23 ms 1912 KB Output is correct
28 Correct 22 ms 1912 KB Output is correct
29 Correct 21 ms 1912 KB Output is correct
30 Correct 24 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1888 KB Output is correct
2 Correct 21 ms 1912 KB Output is correct
3 Correct 21 ms 1824 KB Output is correct
4 Correct 22 ms 1912 KB Output is correct
5 Correct 22 ms 1912 KB Output is correct
6 Correct 22 ms 1912 KB Output is correct
7 Correct 21 ms 1912 KB Output is correct
8 Correct 23 ms 1924 KB Output is correct
9 Correct 21 ms 1912 KB Output is correct
10 Correct 22 ms 1912 KB Output is correct
11 Correct 22 ms 1912 KB Output is correct
12 Correct 23 ms 1912 KB Output is correct
13 Correct 23 ms 1912 KB Output is correct
14 Correct 21 ms 1912 KB Output is correct
15 Correct 22 ms 1912 KB Output is correct
16 Correct 21 ms 1912 KB Output is correct
17 Correct 21 ms 1912 KB Output is correct
18 Correct 22 ms 1912 KB Output is correct
19 Correct 21 ms 1912 KB Output is correct
20 Correct 21 ms 1912 KB Output is correct
21 Correct 21 ms 1912 KB Output is correct
22 Correct 22 ms 1932 KB Output is correct
23 Correct 21 ms 1924 KB Output is correct
24 Correct 22 ms 1912 KB Output is correct
25 Correct 22 ms 1912 KB Output is correct
26 Correct 22 ms 1912 KB Output is correct
27 Correct 23 ms 1912 KB Output is correct
28 Correct 22 ms 1912 KB Output is correct
29 Correct 21 ms 1912 KB Output is correct
30 Correct 24 ms 1912 KB Output is correct
31 Correct 21 ms 2040 KB Output is correct
32 Correct 27 ms 1912 KB Output is correct
33 Correct 23 ms 1912 KB Output is correct
34 Correct 24 ms 1912 KB Output is correct
35 Correct 35 ms 1912 KB Output is correct
36 Correct 39 ms 2040 KB Output is correct
37 Correct 38 ms 1912 KB Output is correct
38 Correct 23 ms 1912 KB Output is correct
39 Correct 27 ms 1916 KB Output is correct
40 Correct 28 ms 1912 KB Output is correct