답안 #56855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56855 2018-07-12T22:55:55 Z ksun48 Asceticism (JOI18_asceticism) C++14
100 / 100
60 ms 2448 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const LL MOD = 1000000007;

LL powmod(LL a, LL n){
	if(n == 0) return 1;
	if(n % 2) return (a * powmod(a, n-1)) % MOD;
	LL c = powmod(a, n/2);
	return (c * c) % MOD;
}

LL inv(LL a){
	return powmod(a, MOD-2);
}
LL fact[110000];
LL invfact[110000];

int main(){
	fact[0] = invfact[0] = 1;
	for(LL i = 1; i < 110000; i++){
		fact[i] = (i * fact[i-1]) % MOD;
		invfact[i] = inv(fact[i]);
	}
	LL n, k;
	cin >> n >> k;
	k--;
	LL ans = 0;
	for(LL i = 0; i <= k; i++){
		LL cur = powmod(k+1-i,n);
		cur = (cur * fact[n+1]) % MOD;
		cur = (cur * invfact[i]) % MOD;
		cur = (cur * invfact[n+1-i]) % MOD;
		if(i % 2) cur *= -1;
		ans = (ans + cur) % MOD;
	}
	ans %= MOD;
	if(ans < 0) ans += MOD;
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2040 KB Output is correct
2 Correct 42 ms 2152 KB Output is correct
3 Correct 40 ms 2152 KB Output is correct
4 Correct 38 ms 2152 KB Output is correct
5 Correct 42 ms 2152 KB Output is correct
6 Correct 37 ms 2184 KB Output is correct
7 Correct 38 ms 2200 KB Output is correct
8 Correct 38 ms 2260 KB Output is correct
9 Correct 38 ms 2260 KB Output is correct
10 Correct 40 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2040 KB Output is correct
2 Correct 42 ms 2152 KB Output is correct
3 Correct 40 ms 2152 KB Output is correct
4 Correct 38 ms 2152 KB Output is correct
5 Correct 42 ms 2152 KB Output is correct
6 Correct 37 ms 2184 KB Output is correct
7 Correct 38 ms 2200 KB Output is correct
8 Correct 38 ms 2260 KB Output is correct
9 Correct 38 ms 2260 KB Output is correct
10 Correct 40 ms 2260 KB Output is correct
11 Correct 40 ms 2260 KB Output is correct
12 Correct 37 ms 2260 KB Output is correct
13 Correct 39 ms 2260 KB Output is correct
14 Correct 40 ms 2260 KB Output is correct
15 Correct 38 ms 2260 KB Output is correct
16 Correct 39 ms 2260 KB Output is correct
17 Correct 39 ms 2288 KB Output is correct
18 Correct 45 ms 2288 KB Output is correct
19 Correct 46 ms 2288 KB Output is correct
20 Correct 40 ms 2288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2040 KB Output is correct
2 Correct 42 ms 2152 KB Output is correct
3 Correct 40 ms 2152 KB Output is correct
4 Correct 38 ms 2152 KB Output is correct
5 Correct 42 ms 2152 KB Output is correct
6 Correct 37 ms 2184 KB Output is correct
7 Correct 38 ms 2200 KB Output is correct
8 Correct 38 ms 2260 KB Output is correct
9 Correct 38 ms 2260 KB Output is correct
10 Correct 40 ms 2260 KB Output is correct
11 Correct 40 ms 2260 KB Output is correct
12 Correct 37 ms 2260 KB Output is correct
13 Correct 39 ms 2260 KB Output is correct
14 Correct 40 ms 2260 KB Output is correct
15 Correct 38 ms 2260 KB Output is correct
16 Correct 39 ms 2260 KB Output is correct
17 Correct 39 ms 2288 KB Output is correct
18 Correct 45 ms 2288 KB Output is correct
19 Correct 46 ms 2288 KB Output is correct
20 Correct 40 ms 2288 KB Output is correct
21 Correct 39 ms 2288 KB Output is correct
22 Correct 42 ms 2288 KB Output is correct
23 Correct 45 ms 2292 KB Output is correct
24 Correct 45 ms 2292 KB Output is correct
25 Correct 41 ms 2292 KB Output is correct
26 Correct 38 ms 2292 KB Output is correct
27 Correct 42 ms 2292 KB Output is correct
28 Correct 40 ms 2388 KB Output is correct
29 Correct 41 ms 2388 KB Output is correct
30 Correct 39 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2040 KB Output is correct
2 Correct 42 ms 2152 KB Output is correct
3 Correct 40 ms 2152 KB Output is correct
4 Correct 38 ms 2152 KB Output is correct
5 Correct 42 ms 2152 KB Output is correct
6 Correct 37 ms 2184 KB Output is correct
7 Correct 38 ms 2200 KB Output is correct
8 Correct 38 ms 2260 KB Output is correct
9 Correct 38 ms 2260 KB Output is correct
10 Correct 40 ms 2260 KB Output is correct
11 Correct 40 ms 2260 KB Output is correct
12 Correct 37 ms 2260 KB Output is correct
13 Correct 39 ms 2260 KB Output is correct
14 Correct 40 ms 2260 KB Output is correct
15 Correct 38 ms 2260 KB Output is correct
16 Correct 39 ms 2260 KB Output is correct
17 Correct 39 ms 2288 KB Output is correct
18 Correct 45 ms 2288 KB Output is correct
19 Correct 46 ms 2288 KB Output is correct
20 Correct 40 ms 2288 KB Output is correct
21 Correct 39 ms 2288 KB Output is correct
22 Correct 42 ms 2288 KB Output is correct
23 Correct 45 ms 2292 KB Output is correct
24 Correct 45 ms 2292 KB Output is correct
25 Correct 41 ms 2292 KB Output is correct
26 Correct 38 ms 2292 KB Output is correct
27 Correct 42 ms 2292 KB Output is correct
28 Correct 40 ms 2388 KB Output is correct
29 Correct 41 ms 2388 KB Output is correct
30 Correct 39 ms 2388 KB Output is correct
31 Correct 38 ms 2388 KB Output is correct
32 Correct 47 ms 2388 KB Output is correct
33 Correct 42 ms 2388 KB Output is correct
34 Correct 44 ms 2388 KB Output is correct
35 Correct 56 ms 2392 KB Output is correct
36 Correct 59 ms 2396 KB Output is correct
37 Correct 60 ms 2400 KB Output is correct
38 Correct 47 ms 2448 KB Output is correct
39 Correct 44 ms 2448 KB Output is correct
40 Correct 48 ms 2448 KB Output is correct