Submission #808681

# Submission time Handle Problem Language Result Execution time Memory
808681 2023-08-05T09:19:25 Z starplat Asceticism (JOI18_asceticism) C++14
100 / 100
16 ms 2648 KB
#include <bits/stdc++.h>
#define int long long
const int mod=1e9+7LL;
using namespace std;
int n,k,fact[100005],inv[100005],invfact[100005],ans;
int fp(int x,int p){
	if (!p) return 1LL;
	int t=fp(x,p/2);
	t=(t*t)%mod;
	if (p&1LL) t*=x;
	return t%mod;
}
int ncr(int x,int p){
	return (fact[x]*invfact[p]%mod*invfact[x-p])%mod;
}
signed main(){
	cin>>n>>k;
	fact[0]=1LL;
	k=n-k;
	for (int i=1;i<=n+1;i++) fact[i]=(fact[i-1]*i)%mod;
	inv[1]=invfact[0]=invfact[1]=1LL;
	for (int i=2;i<=n+1;i++){
		inv[i]=mod-mod/i*inv[mod%i]%mod;
		invfact[i]=(invfact[i-1]*inv[i])%mod;
	}
	for (int i=0;i<=k;i++){
		int cal=ncr(n+1,i)*fp(k+1LL-i,n)%mod;
		if (i&1LL) ans+=(mod-cal);
		else ans+=cal;
		ans%=mod;
	}
	cout<<ans%mod<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 380 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 308 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 288 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 380 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 308 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 16 ms 2644 KB Output is correct
32 Correct 15 ms 2648 KB Output is correct
33 Correct 15 ms 2644 KB Output is correct
34 Correct 13 ms 2612 KB Output is correct
35 Correct 5 ms 2644 KB Output is correct
36 Correct 4 ms 2644 KB Output is correct
37 Correct 4 ms 2604 KB Output is correct
38 Correct 2 ms 692 KB Output is correct
39 Correct 7 ms 2004 KB Output is correct
40 Correct 11 ms 2644 KB Output is correct