Submission #246388

# Submission time Handle Problem Language Result Execution time Memory
246388 2020-07-09T02:58:59 Z wwdd Asceticism (JOI18_asceticism) C++14
100 / 100
47 ms 2808 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 100100;
const ll M = 1e9+7;
inline ll mul(ll a, ll b) {return (a*b)%M;}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {ac = mul(ac,b);}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
inline ll inv(ll v) {return bp(v,M-2);}
ll fp[MN];
ll fac(ll n) {
	if(n <= 1) {return 1;}
	if(fp[n] != -1) {return fp[n];}
	return fp[n] = mul(fac(n-1),n);
}
ll ch(ll n, ll k) {
	if(k < 0 || k > n) {return 0;}
	if(k <= 0 || k >= n) {return 1;}
	return mul(mul(fac(n),inv(fac(k))),inv(fac(n-k)));
}
int main() {
	memset(fp,-1,sizeof(fp));
	ll n,k;
	cin >> n >> k;
	ll res = 0;
	for(int i=0;i<k;i++) {
		ll sgn = (i&1)?-1:1;
		res += sgn*mul(bp(k-i,n),ch(n+1,i));
	}
	res = ((res%M)+M)%M;
	cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 5 ms 1152 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 5 ms 1152 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 5 ms 1152 KB Output is correct
11 Correct 5 ms 1152 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 5 ms 1152 KB Output is correct
14 Correct 5 ms 1152 KB Output is correct
15 Correct 5 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 5 ms 1152 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 6 ms 1152 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 5 ms 1152 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 5 ms 1152 KB Output is correct
11 Correct 5 ms 1152 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 5 ms 1152 KB Output is correct
14 Correct 5 ms 1152 KB Output is correct
15 Correct 5 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 5 ms 1152 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 6 ms 1152 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
21 Correct 6 ms 1152 KB Output is correct
22 Correct 5 ms 1152 KB Output is correct
23 Correct 6 ms 1152 KB Output is correct
24 Correct 5 ms 1152 KB Output is correct
25 Correct 6 ms 1280 KB Output is correct
26 Correct 6 ms 1152 KB Output is correct
27 Correct 5 ms 1152 KB Output is correct
28 Correct 5 ms 1152 KB Output is correct
29 Correct 5 ms 1152 KB Output is correct
30 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1152 KB Output is correct
7 Correct 5 ms 1152 KB Output is correct
8 Correct 5 ms 1152 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 5 ms 1152 KB Output is correct
11 Correct 5 ms 1152 KB Output is correct
12 Correct 6 ms 1152 KB Output is correct
13 Correct 5 ms 1152 KB Output is correct
14 Correct 5 ms 1152 KB Output is correct
15 Correct 5 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 5 ms 1152 KB Output is correct
18 Correct 5 ms 1152 KB Output is correct
19 Correct 6 ms 1152 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
21 Correct 6 ms 1152 KB Output is correct
22 Correct 5 ms 1152 KB Output is correct
23 Correct 6 ms 1152 KB Output is correct
24 Correct 5 ms 1152 KB Output is correct
25 Correct 6 ms 1280 KB Output is correct
26 Correct 6 ms 1152 KB Output is correct
27 Correct 5 ms 1152 KB Output is correct
28 Correct 5 ms 1152 KB Output is correct
29 Correct 5 ms 1152 KB Output is correct
30 Correct 5 ms 1152 KB Output is correct
31 Correct 5 ms 1152 KB Output is correct
32 Correct 6 ms 2688 KB Output is correct
33 Correct 9 ms 2688 KB Output is correct
34 Correct 13 ms 2688 KB Output is correct
35 Correct 38 ms 2688 KB Output is correct
36 Correct 42 ms 2808 KB Output is correct
37 Correct 47 ms 2688 KB Output is correct
38 Correct 10 ms 1408 KB Output is correct
39 Correct 18 ms 2176 KB Output is correct
40 Correct 22 ms 2688 KB Output is correct