Submission #459666

# Submission time Handle Problem Language Result Execution time Memory
459666 2021-08-08T23:57:55 Z JovanB Asceticism (JOI18_asceticism) C++17
100 / 100
70 ms 2020 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define pb push_back
 
const int MOD = 1000000007;
 
int add(int a, int b){
    a += b;
    if(a >= MOD) a -= MOD;
    return a;
}
 
int mul(int a, int b){
    return (1LL*a*b)%MOD;
}
 
int pw(int a, int b){
    if(b == 0) return 1;
    int res = pw(a, b/2);
    res = mul(res, res);
    if(b%2) res = mul(res, a);
    return res;
}
 
int fak[200005];
int inv[200005];
 
int bin(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    int res = fak[n];
    res = mul(res, inv[k]);
    res = mul(res, inv[n-k]);
    return res;
}
 
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;
 
    int n, m;
    cin >> n >> m;
    m = n-m;
    int res = 0;
    fak[0] = inv[0] = 1;
    for(int i=1; i<=200000; i++){
        fak[i] = mul(fak[i-1], i);
        inv[i] = pw(fak[i], MOD-2);
    }
    for(int k=0; k<=m+1; k++){
        int tr = pw(m+1-k, n);
        tr = mul(tr, bin(n+1, k));
        if(k%2) res = add(res, MOD-tr);
        else res = add(res, tr);
    }
    cout << res << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1860 KB Output is correct
2 Correct 52 ms 1768 KB Output is correct
3 Correct 52 ms 1812 KB Output is correct
4 Correct 52 ms 1732 KB Output is correct
5 Correct 53 ms 2020 KB Output is correct
6 Correct 52 ms 1764 KB Output is correct
7 Correct 52 ms 1836 KB Output is correct
8 Correct 52 ms 1860 KB Output is correct
9 Correct 52 ms 1860 KB Output is correct
10 Correct 53 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1860 KB Output is correct
2 Correct 52 ms 1768 KB Output is correct
3 Correct 52 ms 1812 KB Output is correct
4 Correct 52 ms 1732 KB Output is correct
5 Correct 53 ms 2020 KB Output is correct
6 Correct 52 ms 1764 KB Output is correct
7 Correct 52 ms 1836 KB Output is correct
8 Correct 52 ms 1860 KB Output is correct
9 Correct 52 ms 1860 KB Output is correct
10 Correct 53 ms 1792 KB Output is correct
11 Correct 52 ms 1744 KB Output is correct
12 Correct 54 ms 1820 KB Output is correct
13 Correct 54 ms 1824 KB Output is correct
14 Correct 53 ms 1800 KB Output is correct
15 Correct 53 ms 1828 KB Output is correct
16 Correct 55 ms 1800 KB Output is correct
17 Correct 52 ms 1848 KB Output is correct
18 Correct 52 ms 1868 KB Output is correct
19 Correct 54 ms 1808 KB Output is correct
20 Correct 53 ms 1928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1860 KB Output is correct
2 Correct 52 ms 1768 KB Output is correct
3 Correct 52 ms 1812 KB Output is correct
4 Correct 52 ms 1732 KB Output is correct
5 Correct 53 ms 2020 KB Output is correct
6 Correct 52 ms 1764 KB Output is correct
7 Correct 52 ms 1836 KB Output is correct
8 Correct 52 ms 1860 KB Output is correct
9 Correct 52 ms 1860 KB Output is correct
10 Correct 53 ms 1792 KB Output is correct
11 Correct 52 ms 1744 KB Output is correct
12 Correct 54 ms 1820 KB Output is correct
13 Correct 54 ms 1824 KB Output is correct
14 Correct 53 ms 1800 KB Output is correct
15 Correct 53 ms 1828 KB Output is correct
16 Correct 55 ms 1800 KB Output is correct
17 Correct 52 ms 1848 KB Output is correct
18 Correct 52 ms 1868 KB Output is correct
19 Correct 54 ms 1808 KB Output is correct
20 Correct 53 ms 1928 KB Output is correct
21 Correct 52 ms 1780 KB Output is correct
22 Correct 53 ms 1808 KB Output is correct
23 Correct 52 ms 1800 KB Output is correct
24 Correct 54 ms 1800 KB Output is correct
25 Correct 52 ms 1796 KB Output is correct
26 Correct 52 ms 1764 KB Output is correct
27 Correct 53 ms 1796 KB Output is correct
28 Correct 52 ms 1776 KB Output is correct
29 Correct 52 ms 1732 KB Output is correct
30 Correct 52 ms 1856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1860 KB Output is correct
2 Correct 52 ms 1768 KB Output is correct
3 Correct 52 ms 1812 KB Output is correct
4 Correct 52 ms 1732 KB Output is correct
5 Correct 53 ms 2020 KB Output is correct
6 Correct 52 ms 1764 KB Output is correct
7 Correct 52 ms 1836 KB Output is correct
8 Correct 52 ms 1860 KB Output is correct
9 Correct 52 ms 1860 KB Output is correct
10 Correct 53 ms 1792 KB Output is correct
11 Correct 52 ms 1744 KB Output is correct
12 Correct 54 ms 1820 KB Output is correct
13 Correct 54 ms 1824 KB Output is correct
14 Correct 53 ms 1800 KB Output is correct
15 Correct 53 ms 1828 KB Output is correct
16 Correct 55 ms 1800 KB Output is correct
17 Correct 52 ms 1848 KB Output is correct
18 Correct 52 ms 1868 KB Output is correct
19 Correct 54 ms 1808 KB Output is correct
20 Correct 53 ms 1928 KB Output is correct
21 Correct 52 ms 1780 KB Output is correct
22 Correct 53 ms 1808 KB Output is correct
23 Correct 52 ms 1800 KB Output is correct
24 Correct 54 ms 1800 KB Output is correct
25 Correct 52 ms 1796 KB Output is correct
26 Correct 52 ms 1764 KB Output is correct
27 Correct 53 ms 1796 KB Output is correct
28 Correct 52 ms 1776 KB Output is correct
29 Correct 52 ms 1732 KB Output is correct
30 Correct 52 ms 1856 KB Output is correct
31 Correct 68 ms 1812 KB Output is correct
32 Correct 70 ms 1824 KB Output is correct
33 Correct 67 ms 1860 KB Output is correct
34 Correct 65 ms 1772 KB Output is correct
35 Correct 55 ms 1824 KB Output is correct
36 Correct 53 ms 1812 KB Output is correct
37 Correct 52 ms 1860 KB Output is correct
38 Correct 54 ms 1788 KB Output is correct
39 Correct 58 ms 1804 KB Output is correct
40 Correct 65 ms 1836 KB Output is correct