답안 #342367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342367 2021-01-02T01:11:40 Z jovan_b Asceticism (JOI18_asceticism) C++17
49 / 100
49 ms 1152 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[100005];
int inv[100005];

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<=100000; 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1132 KB Output is correct
2 Correct 31 ms 1132 KB Output is correct
3 Correct 32 ms 1132 KB Output is correct
4 Correct 31 ms 1132 KB Output is correct
5 Correct 31 ms 1132 KB Output is correct
6 Correct 31 ms 1132 KB Output is correct
7 Correct 31 ms 1132 KB Output is correct
8 Correct 38 ms 1132 KB Output is correct
9 Correct 32 ms 1132 KB Output is correct
10 Correct 32 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1132 KB Output is correct
2 Correct 31 ms 1132 KB Output is correct
3 Correct 32 ms 1132 KB Output is correct
4 Correct 31 ms 1132 KB Output is correct
5 Correct 31 ms 1132 KB Output is correct
6 Correct 31 ms 1132 KB Output is correct
7 Correct 31 ms 1132 KB Output is correct
8 Correct 38 ms 1132 KB Output is correct
9 Correct 32 ms 1132 KB Output is correct
10 Correct 32 ms 1132 KB Output is correct
11 Correct 32 ms 1132 KB Output is correct
12 Correct 31 ms 1132 KB Output is correct
13 Correct 32 ms 1132 KB Output is correct
14 Correct 32 ms 1132 KB Output is correct
15 Correct 32 ms 1132 KB Output is correct
16 Correct 32 ms 1132 KB Output is correct
17 Correct 31 ms 1132 KB Output is correct
18 Correct 33 ms 1132 KB Output is correct
19 Correct 32 ms 1132 KB Output is correct
20 Correct 32 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1132 KB Output is correct
2 Correct 31 ms 1132 KB Output is correct
3 Correct 32 ms 1132 KB Output is correct
4 Correct 31 ms 1132 KB Output is correct
5 Correct 31 ms 1132 KB Output is correct
6 Correct 31 ms 1132 KB Output is correct
7 Correct 31 ms 1132 KB Output is correct
8 Correct 38 ms 1132 KB Output is correct
9 Correct 32 ms 1132 KB Output is correct
10 Correct 32 ms 1132 KB Output is correct
11 Correct 32 ms 1132 KB Output is correct
12 Correct 31 ms 1132 KB Output is correct
13 Correct 32 ms 1132 KB Output is correct
14 Correct 32 ms 1132 KB Output is correct
15 Correct 32 ms 1132 KB Output is correct
16 Correct 32 ms 1132 KB Output is correct
17 Correct 31 ms 1132 KB Output is correct
18 Correct 33 ms 1132 KB Output is correct
19 Correct 32 ms 1132 KB Output is correct
20 Correct 32 ms 1132 KB Output is correct
21 Correct 32 ms 1132 KB Output is correct
22 Correct 31 ms 1132 KB Output is correct
23 Correct 31 ms 1132 KB Output is correct
24 Correct 35 ms 1152 KB Output is correct
25 Correct 31 ms 1132 KB Output is correct
26 Correct 31 ms 1132 KB Output is correct
27 Correct 32 ms 1132 KB Output is correct
28 Correct 31 ms 1132 KB Output is correct
29 Correct 32 ms 1132 KB Output is correct
30 Correct 31 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1132 KB Output is correct
2 Correct 31 ms 1132 KB Output is correct
3 Correct 32 ms 1132 KB Output is correct
4 Correct 31 ms 1132 KB Output is correct
5 Correct 31 ms 1132 KB Output is correct
6 Correct 31 ms 1132 KB Output is correct
7 Correct 31 ms 1132 KB Output is correct
8 Correct 38 ms 1132 KB Output is correct
9 Correct 32 ms 1132 KB Output is correct
10 Correct 32 ms 1132 KB Output is correct
11 Correct 32 ms 1132 KB Output is correct
12 Correct 31 ms 1132 KB Output is correct
13 Correct 32 ms 1132 KB Output is correct
14 Correct 32 ms 1132 KB Output is correct
15 Correct 32 ms 1132 KB Output is correct
16 Correct 32 ms 1132 KB Output is correct
17 Correct 31 ms 1132 KB Output is correct
18 Correct 33 ms 1132 KB Output is correct
19 Correct 32 ms 1132 KB Output is correct
20 Correct 32 ms 1132 KB Output is correct
21 Correct 32 ms 1132 KB Output is correct
22 Correct 31 ms 1132 KB Output is correct
23 Correct 31 ms 1132 KB Output is correct
24 Correct 35 ms 1152 KB Output is correct
25 Correct 31 ms 1132 KB Output is correct
26 Correct 31 ms 1132 KB Output is correct
27 Correct 32 ms 1132 KB Output is correct
28 Correct 31 ms 1132 KB Output is correct
29 Correct 32 ms 1132 KB Output is correct
30 Correct 31 ms 1132 KB Output is correct
31 Incorrect 49 ms 1132 KB Output isn't correct
32 Halted 0 ms 0 KB -