답안 #100570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100570 2019-03-12T10:28:16 Z JPN20 Asceticism (JOI18_asceticism) C++17
100 / 100
199 ms 3672 KB
#include <bits/stdc++.h>
using namespace std;

long long fact[200009], inv[200009], mod = 1000000007;

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 32; i++) {
		if ((b & (1LL << i)) != 0) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

void init() {
	fact[0] = 1; for (int i = 1; i <= 200000; i++) fact[i] = (1LL * i * fact[i - 1]) % mod;
	for (int i = 0; i <= 200000; i++) inv[i] = modpow(fact[i], mod - 2, mod);
}

long long ncr(long long n, long long r) {
	if (r < 0 || n < r) return 0;
	return (fact[n] * inv[r] % mod) * inv[n - r] % mod;
}

long long solve(long long A, long long B) {
	long long sum = 0, c = 1;
	for (int i = A; i >= 1; i--) {
		long long V1 = modpow(i, A + B, mod);
		long long V2 = ncr(A + B + 1, A - i);
		sum += c * V1 * V2; sum += mod * mod; sum %= mod;
		c *= -1;
	}
	return sum;
}

int main() {
	init();
	long long N, K; cin >> N >> K;
	cout << solve(K, N - K) << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 3448 KB Output is correct
2 Correct 130 ms 3448 KB Output is correct
3 Correct 131 ms 3448 KB Output is correct
4 Correct 142 ms 3452 KB Output is correct
5 Correct 134 ms 3448 KB Output is correct
6 Correct 135 ms 3448 KB Output is correct
7 Correct 135 ms 3448 KB Output is correct
8 Correct 134 ms 3564 KB Output is correct
9 Correct 140 ms 3424 KB Output is correct
10 Correct 134 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 3448 KB Output is correct
2 Correct 130 ms 3448 KB Output is correct
3 Correct 131 ms 3448 KB Output is correct
4 Correct 142 ms 3452 KB Output is correct
5 Correct 134 ms 3448 KB Output is correct
6 Correct 135 ms 3448 KB Output is correct
7 Correct 135 ms 3448 KB Output is correct
8 Correct 134 ms 3564 KB Output is correct
9 Correct 140 ms 3424 KB Output is correct
10 Correct 134 ms 3448 KB Output is correct
11 Correct 132 ms 3428 KB Output is correct
12 Correct 139 ms 3576 KB Output is correct
13 Correct 150 ms 3440 KB Output is correct
14 Correct 130 ms 3420 KB Output is correct
15 Correct 133 ms 3460 KB Output is correct
16 Correct 138 ms 3484 KB Output is correct
17 Correct 131 ms 3420 KB Output is correct
18 Correct 135 ms 3476 KB Output is correct
19 Correct 136 ms 3640 KB Output is correct
20 Correct 136 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 3448 KB Output is correct
2 Correct 130 ms 3448 KB Output is correct
3 Correct 131 ms 3448 KB Output is correct
4 Correct 142 ms 3452 KB Output is correct
5 Correct 134 ms 3448 KB Output is correct
6 Correct 135 ms 3448 KB Output is correct
7 Correct 135 ms 3448 KB Output is correct
8 Correct 134 ms 3564 KB Output is correct
9 Correct 140 ms 3424 KB Output is correct
10 Correct 134 ms 3448 KB Output is correct
11 Correct 132 ms 3428 KB Output is correct
12 Correct 139 ms 3576 KB Output is correct
13 Correct 150 ms 3440 KB Output is correct
14 Correct 130 ms 3420 KB Output is correct
15 Correct 133 ms 3460 KB Output is correct
16 Correct 138 ms 3484 KB Output is correct
17 Correct 131 ms 3420 KB Output is correct
18 Correct 135 ms 3476 KB Output is correct
19 Correct 136 ms 3640 KB Output is correct
20 Correct 136 ms 3448 KB Output is correct
21 Correct 138 ms 3448 KB Output is correct
22 Correct 135 ms 3440 KB Output is correct
23 Correct 136 ms 3512 KB Output is correct
24 Correct 133 ms 3476 KB Output is correct
25 Correct 137 ms 3448 KB Output is correct
26 Correct 136 ms 3672 KB Output is correct
27 Correct 137 ms 3448 KB Output is correct
28 Correct 139 ms 3524 KB Output is correct
29 Correct 135 ms 3444 KB Output is correct
30 Correct 139 ms 3468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 3448 KB Output is correct
2 Correct 130 ms 3448 KB Output is correct
3 Correct 131 ms 3448 KB Output is correct
4 Correct 142 ms 3452 KB Output is correct
5 Correct 134 ms 3448 KB Output is correct
6 Correct 135 ms 3448 KB Output is correct
7 Correct 135 ms 3448 KB Output is correct
8 Correct 134 ms 3564 KB Output is correct
9 Correct 140 ms 3424 KB Output is correct
10 Correct 134 ms 3448 KB Output is correct
11 Correct 132 ms 3428 KB Output is correct
12 Correct 139 ms 3576 KB Output is correct
13 Correct 150 ms 3440 KB Output is correct
14 Correct 130 ms 3420 KB Output is correct
15 Correct 133 ms 3460 KB Output is correct
16 Correct 138 ms 3484 KB Output is correct
17 Correct 131 ms 3420 KB Output is correct
18 Correct 135 ms 3476 KB Output is correct
19 Correct 136 ms 3640 KB Output is correct
20 Correct 136 ms 3448 KB Output is correct
21 Correct 138 ms 3448 KB Output is correct
22 Correct 135 ms 3440 KB Output is correct
23 Correct 136 ms 3512 KB Output is correct
24 Correct 133 ms 3476 KB Output is correct
25 Correct 137 ms 3448 KB Output is correct
26 Correct 136 ms 3672 KB Output is correct
27 Correct 137 ms 3448 KB Output is correct
28 Correct 139 ms 3524 KB Output is correct
29 Correct 135 ms 3444 KB Output is correct
30 Correct 139 ms 3468 KB Output is correct
31 Correct 135 ms 3476 KB Output is correct
32 Correct 139 ms 3500 KB Output is correct
33 Correct 143 ms 3448 KB Output is correct
34 Correct 162 ms 3620 KB Output is correct
35 Correct 190 ms 3592 KB Output is correct
36 Correct 197 ms 3584 KB Output is correct
37 Correct 199 ms 3448 KB Output is correct
38 Correct 140 ms 3516 KB Output is correct
39 Correct 167 ms 3448 KB Output is correct
40 Correct 169 ms 3448 KB Output is correct