답안 #914862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914862 2024-01-22T19:01:15 Z amirhoseinfar1385 Asceticism (JOI18_asceticism) C++17
100 / 100
23 ms 2140 KB
#include<bits/stdc++.h>
using namespace std;
const long long maxn=100000+10;
long long mod=1e9+7;
long long fact[maxn],revfact[maxn];

long long mypow(long long m,long long y){
	if(y==0){
		return 1;
	}
	long long p=mypow(m,(y>>1));
	p*=p;
	p%=mod;
	if(y&1){
		p*=m;
		p%=mod;
	}
	return p;
}

void aval(){
	fact[0]=1;
	for(long long i=1;i<maxn;i++){
		fact[i]=1ll*fact[i-1]*i%mod;
	}
	revfact[maxn-1]=mypow(fact[maxn-1],mod-2);
	for(long long i=maxn-2;i>=0;i--){
		revfact[i]=1ll*revfact[i+1]*(i+1)%mod;
	}
}
long long c(long long i,long long j){
	if(i<0||j<0||i<j){
		return 0;
	}
	return 1ll*fact[i]*revfact[j]%mod*revfact[i-j]%mod;
}

int main(){
	aval();
	long long n,k;
	cin>>n>>k;
	long long res=0;
	for(long long i=k;i>=1;i--){
		long long fake=mypow(i,n)*c(n+1,k-i)%mod;
		if((k-i)&1){
			res-=fake;
		}
		else{
			res+=fake;
		}
		//cout<<i<<" "<<fake<<" "<<mypow(i,n)<<" "<<c(n+1,k-i)<<endl;
	}
//	cout<<res<<endl;
	res+=1000000*mod;
	res%=mod;
//	res=abs(res);
//	res%=mod;
//	res = ((res % mod) + mod) % mod;
	cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 3 ms 1884 KB Output is correct
3 Correct 3 ms 1880 KB Output is correct
4 Correct 3 ms 1884 KB Output is correct
5 Correct 3 ms 1884 KB Output is correct
6 Correct 3 ms 1884 KB Output is correct
7 Correct 3 ms 1884 KB Output is correct
8 Correct 3 ms 1884 KB Output is correct
9 Correct 3 ms 1880 KB Output is correct
10 Correct 3 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 3 ms 1884 KB Output is correct
3 Correct 3 ms 1880 KB Output is correct
4 Correct 3 ms 1884 KB Output is correct
5 Correct 3 ms 1884 KB Output is correct
6 Correct 3 ms 1884 KB Output is correct
7 Correct 3 ms 1884 KB Output is correct
8 Correct 3 ms 1884 KB Output is correct
9 Correct 3 ms 1880 KB Output is correct
10 Correct 3 ms 1880 KB Output is correct
11 Correct 3 ms 1884 KB Output is correct
12 Correct 3 ms 1884 KB Output is correct
13 Correct 3 ms 1816 KB Output is correct
14 Correct 3 ms 1880 KB Output is correct
15 Correct 3 ms 1884 KB Output is correct
16 Correct 3 ms 1884 KB Output is correct
17 Correct 3 ms 1884 KB Output is correct
18 Correct 4 ms 1884 KB Output is correct
19 Correct 3 ms 1884 KB Output is correct
20 Correct 3 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 3 ms 1884 KB Output is correct
3 Correct 3 ms 1880 KB Output is correct
4 Correct 3 ms 1884 KB Output is correct
5 Correct 3 ms 1884 KB Output is correct
6 Correct 3 ms 1884 KB Output is correct
7 Correct 3 ms 1884 KB Output is correct
8 Correct 3 ms 1884 KB Output is correct
9 Correct 3 ms 1880 KB Output is correct
10 Correct 3 ms 1880 KB Output is correct
11 Correct 3 ms 1884 KB Output is correct
12 Correct 3 ms 1884 KB Output is correct
13 Correct 3 ms 1816 KB Output is correct
14 Correct 3 ms 1880 KB Output is correct
15 Correct 3 ms 1884 KB Output is correct
16 Correct 3 ms 1884 KB Output is correct
17 Correct 3 ms 1884 KB Output is correct
18 Correct 4 ms 1884 KB Output is correct
19 Correct 3 ms 1884 KB Output is correct
20 Correct 3 ms 1884 KB Output is correct
21 Correct 3 ms 2140 KB Output is correct
22 Correct 3 ms 2140 KB Output is correct
23 Correct 3 ms 1884 KB Output is correct
24 Correct 3 ms 2140 KB Output is correct
25 Correct 3 ms 2004 KB Output is correct
26 Correct 3 ms 1880 KB Output is correct
27 Correct 3 ms 2000 KB Output is correct
28 Correct 4 ms 1884 KB Output is correct
29 Correct 3 ms 1884 KB Output is correct
30 Correct 3 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 3 ms 1884 KB Output is correct
3 Correct 3 ms 1880 KB Output is correct
4 Correct 3 ms 1884 KB Output is correct
5 Correct 3 ms 1884 KB Output is correct
6 Correct 3 ms 1884 KB Output is correct
7 Correct 3 ms 1884 KB Output is correct
8 Correct 3 ms 1884 KB Output is correct
9 Correct 3 ms 1880 KB Output is correct
10 Correct 3 ms 1880 KB Output is correct
11 Correct 3 ms 1884 KB Output is correct
12 Correct 3 ms 1884 KB Output is correct
13 Correct 3 ms 1816 KB Output is correct
14 Correct 3 ms 1880 KB Output is correct
15 Correct 3 ms 1884 KB Output is correct
16 Correct 3 ms 1884 KB Output is correct
17 Correct 3 ms 1884 KB Output is correct
18 Correct 4 ms 1884 KB Output is correct
19 Correct 3 ms 1884 KB Output is correct
20 Correct 3 ms 1884 KB Output is correct
21 Correct 3 ms 2140 KB Output is correct
22 Correct 3 ms 2140 KB Output is correct
23 Correct 3 ms 1884 KB Output is correct
24 Correct 3 ms 2140 KB Output is correct
25 Correct 3 ms 2004 KB Output is correct
26 Correct 3 ms 1880 KB Output is correct
27 Correct 3 ms 2000 KB Output is correct
28 Correct 4 ms 1884 KB Output is correct
29 Correct 3 ms 1884 KB Output is correct
30 Correct 3 ms 1884 KB Output is correct
31 Correct 3 ms 1884 KB Output is correct
32 Correct 3 ms 1980 KB Output is correct
33 Correct 4 ms 1884 KB Output is correct
34 Correct 6 ms 1900 KB Output is correct
35 Correct 19 ms 1888 KB Output is correct
36 Correct 21 ms 1884 KB Output is correct
37 Correct 23 ms 1884 KB Output is correct
38 Correct 6 ms 1884 KB Output is correct
39 Correct 9 ms 1884 KB Output is correct
40 Correct 12 ms 2140 KB Output is correct