답안 #203270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203270 2020-02-20T03:53:15 Z tri Asceticism (JOI18_asceticism) C++14
100 / 100
16 ms 1928 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

const int MAXN = 1e5 + 10;
const ll MOD = 1e9 + 7;

ll fact[MAXN];
ll iFact[MAXN];

ll comb(int n, int k) {
    return fact[n] * iFact[k] % MOD * iFact[n - k] % MOD;
}

ll binExp(ll base, int exp) {
    base %= MOD;

    ll prod = 1;

    while (exp > 0) {
        if (exp & 1) {
            prod = prod * base % MOD;
        }
        base = base * base % MOD;
        exp >>= 1;
    }

    return prod;
}

int main() {
    fact[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    iFact[MAXN - 1] = 549915853;

    assert(fact[MAXN - 1] * iFact[MAXN - 1] % MOD == 1);

    for (int i = MAXN - 2; i >= 0; i--) {
        iFact[i] = (i + 1) * iFact[i + 1] % MOD;
        assert(fact[i] * iFact[i] % MOD == 1);
    }

//    cout << comb(23134, 242) << endl;

//    cout << binExp(2342, 124515) << endl;

    int N, K;
    cin >> N >> K;
    K--;

    ll sum = 0;
    for (int i = 0; i <= K; i++) {
        ll val = comb(N + 1, i) * binExp(K + 1 - i, N) % MOD;
//        cout << val << endl;
        if (i % 2 == 0) {
            sum = (sum + val) % MOD;
        } else {
            sum = (sum - val + MOD) % MOD;
        }
    }

    cout << sum << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1912 KB Output is correct
2 Correct 7 ms 1784 KB Output is correct
3 Correct 7 ms 1912 KB Output is correct
4 Correct 7 ms 1912 KB Output is correct
5 Correct 7 ms 1912 KB Output is correct
6 Correct 8 ms 1912 KB Output is correct
7 Correct 7 ms 1912 KB Output is correct
8 Correct 7 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1912 KB Output is correct
2 Correct 7 ms 1784 KB Output is correct
3 Correct 7 ms 1912 KB Output is correct
4 Correct 7 ms 1912 KB Output is correct
5 Correct 7 ms 1912 KB Output is correct
6 Correct 8 ms 1912 KB Output is correct
7 Correct 7 ms 1912 KB Output is correct
8 Correct 7 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
11 Correct 8 ms 1912 KB Output is correct
12 Correct 7 ms 1912 KB Output is correct
13 Correct 7 ms 1916 KB Output is correct
14 Correct 7 ms 1912 KB Output is correct
15 Correct 7 ms 1912 KB Output is correct
16 Correct 7 ms 1912 KB Output is correct
17 Correct 7 ms 1912 KB Output is correct
18 Correct 7 ms 1912 KB Output is correct
19 Correct 7 ms 1912 KB Output is correct
20 Correct 7 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1912 KB Output is correct
2 Correct 7 ms 1784 KB Output is correct
3 Correct 7 ms 1912 KB Output is correct
4 Correct 7 ms 1912 KB Output is correct
5 Correct 7 ms 1912 KB Output is correct
6 Correct 8 ms 1912 KB Output is correct
7 Correct 7 ms 1912 KB Output is correct
8 Correct 7 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
11 Correct 8 ms 1912 KB Output is correct
12 Correct 7 ms 1912 KB Output is correct
13 Correct 7 ms 1916 KB Output is correct
14 Correct 7 ms 1912 KB Output is correct
15 Correct 7 ms 1912 KB Output is correct
16 Correct 7 ms 1912 KB Output is correct
17 Correct 7 ms 1912 KB Output is correct
18 Correct 7 ms 1912 KB Output is correct
19 Correct 7 ms 1912 KB Output is correct
20 Correct 7 ms 1912 KB Output is correct
21 Correct 7 ms 1912 KB Output is correct
22 Correct 7 ms 1912 KB Output is correct
23 Correct 7 ms 1828 KB Output is correct
24 Correct 7 ms 1908 KB Output is correct
25 Correct 7 ms 1912 KB Output is correct
26 Correct 7 ms 1912 KB Output is correct
27 Correct 7 ms 1912 KB Output is correct
28 Correct 7 ms 1912 KB Output is correct
29 Correct 7 ms 1912 KB Output is correct
30 Correct 7 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1912 KB Output is correct
2 Correct 7 ms 1784 KB Output is correct
3 Correct 7 ms 1912 KB Output is correct
4 Correct 7 ms 1912 KB Output is correct
5 Correct 7 ms 1912 KB Output is correct
6 Correct 8 ms 1912 KB Output is correct
7 Correct 7 ms 1912 KB Output is correct
8 Correct 7 ms 1912 KB Output is correct
9 Correct 7 ms 1912 KB Output is correct
10 Correct 7 ms 1912 KB Output is correct
11 Correct 8 ms 1912 KB Output is correct
12 Correct 7 ms 1912 KB Output is correct
13 Correct 7 ms 1916 KB Output is correct
14 Correct 7 ms 1912 KB Output is correct
15 Correct 7 ms 1912 KB Output is correct
16 Correct 7 ms 1912 KB Output is correct
17 Correct 7 ms 1912 KB Output is correct
18 Correct 7 ms 1912 KB Output is correct
19 Correct 7 ms 1912 KB Output is correct
20 Correct 7 ms 1912 KB Output is correct
21 Correct 7 ms 1912 KB Output is correct
22 Correct 7 ms 1912 KB Output is correct
23 Correct 7 ms 1828 KB Output is correct
24 Correct 7 ms 1908 KB Output is correct
25 Correct 7 ms 1912 KB Output is correct
26 Correct 7 ms 1912 KB Output is correct
27 Correct 7 ms 1912 KB Output is correct
28 Correct 7 ms 1912 KB Output is correct
29 Correct 7 ms 1912 KB Output is correct
30 Correct 7 ms 1912 KB Output is correct
31 Correct 7 ms 1916 KB Output is correct
32 Correct 7 ms 1912 KB Output is correct
33 Correct 7 ms 1912 KB Output is correct
34 Correct 9 ms 1928 KB Output is correct
35 Correct 14 ms 1912 KB Output is correct
36 Correct 15 ms 1912 KB Output is correct
37 Correct 16 ms 1912 KB Output is correct
38 Correct 8 ms 1912 KB Output is correct
39 Correct 10 ms 1912 KB Output is correct
40 Correct 11 ms 1912 KB Output is correct