Submission #43997

# Submission time Handle Problem Language Result Execution time Memory
43997 2018-03-29T09:38:10 Z zscoder Asceticism (JOI18_asceticism) C++17
100 / 100
68 ms 2372 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

const int MOD = 1e9 + 7;

int add(int a, int b)
{
	a+=b; while(a>=MOD) a-=MOD;
	return a;
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a); b>>=1;
	}
	return r;
}

int ifact[111111];
int fact[111111];
int pow2[111111];
int ipow2[111111];
int choose(int n, int r)
{
	if(r<0) return 0;
	if(n<r) return 0;
	if(r==0) return 1;
	return mult(fact[n],mult(ifact[r],ifact[n-r]));
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	fact[0]=ifact[0]=1; pow2[0]=ipow2[0]=1;
	for(int i=1;i<=100111;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		ipow2[i] = modpow(pow2[i], MOD-2);
	}
	for(int i=1;i<=100111;i++) 
	{
		fact[i]=mult(fact[i-1],i); ifact[i] = modpow(fact[i],MOD-2);
	}
	int ans=0;
	m--;
	for(int i=0;i<=m+1;i++)
	{
		ans = add(ans, mult(modpow(MOD-1,i),mult(choose(n+1,i),modpow(m-i+1,n))));
	}
	cout<<ans<<'\n';
}

# Verdict Execution time Memory Grader output
1 Correct 45 ms 1912 KB Output is correct
2 Correct 46 ms 2024 KB Output is correct
3 Correct 44 ms 2076 KB Output is correct
4 Correct 45 ms 2104 KB Output is correct
5 Correct 45 ms 2104 KB Output is correct
6 Correct 45 ms 2104 KB Output is correct
7 Correct 45 ms 2104 KB Output is correct
8 Correct 45 ms 2196 KB Output is correct
9 Correct 44 ms 2196 KB Output is correct
10 Correct 44 ms 2372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1912 KB Output is correct
2 Correct 46 ms 2024 KB Output is correct
3 Correct 44 ms 2076 KB Output is correct
4 Correct 45 ms 2104 KB Output is correct
5 Correct 45 ms 2104 KB Output is correct
6 Correct 45 ms 2104 KB Output is correct
7 Correct 45 ms 2104 KB Output is correct
8 Correct 45 ms 2196 KB Output is correct
9 Correct 44 ms 2196 KB Output is correct
10 Correct 44 ms 2372 KB Output is correct
11 Correct 45 ms 2372 KB Output is correct
12 Correct 44 ms 2372 KB Output is correct
13 Correct 45 ms 2372 KB Output is correct
14 Correct 44 ms 2372 KB Output is correct
15 Correct 44 ms 2372 KB Output is correct
16 Correct 45 ms 2372 KB Output is correct
17 Correct 44 ms 2372 KB Output is correct
18 Correct 45 ms 2372 KB Output is correct
19 Correct 46 ms 2372 KB Output is correct
20 Correct 45 ms 2372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1912 KB Output is correct
2 Correct 46 ms 2024 KB Output is correct
3 Correct 44 ms 2076 KB Output is correct
4 Correct 45 ms 2104 KB Output is correct
5 Correct 45 ms 2104 KB Output is correct
6 Correct 45 ms 2104 KB Output is correct
7 Correct 45 ms 2104 KB Output is correct
8 Correct 45 ms 2196 KB Output is correct
9 Correct 44 ms 2196 KB Output is correct
10 Correct 44 ms 2372 KB Output is correct
11 Correct 45 ms 2372 KB Output is correct
12 Correct 44 ms 2372 KB Output is correct
13 Correct 45 ms 2372 KB Output is correct
14 Correct 44 ms 2372 KB Output is correct
15 Correct 44 ms 2372 KB Output is correct
16 Correct 45 ms 2372 KB Output is correct
17 Correct 44 ms 2372 KB Output is correct
18 Correct 45 ms 2372 KB Output is correct
19 Correct 46 ms 2372 KB Output is correct
20 Correct 45 ms 2372 KB Output is correct
21 Correct 45 ms 2372 KB Output is correct
22 Correct 45 ms 2372 KB Output is correct
23 Correct 45 ms 2372 KB Output is correct
24 Correct 45 ms 2372 KB Output is correct
25 Correct 48 ms 2372 KB Output is correct
26 Correct 45 ms 2372 KB Output is correct
27 Correct 45 ms 2372 KB Output is correct
28 Correct 45 ms 2372 KB Output is correct
29 Correct 44 ms 2372 KB Output is correct
30 Correct 45 ms 2372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1912 KB Output is correct
2 Correct 46 ms 2024 KB Output is correct
3 Correct 44 ms 2076 KB Output is correct
4 Correct 45 ms 2104 KB Output is correct
5 Correct 45 ms 2104 KB Output is correct
6 Correct 45 ms 2104 KB Output is correct
7 Correct 45 ms 2104 KB Output is correct
8 Correct 45 ms 2196 KB Output is correct
9 Correct 44 ms 2196 KB Output is correct
10 Correct 44 ms 2372 KB Output is correct
11 Correct 45 ms 2372 KB Output is correct
12 Correct 44 ms 2372 KB Output is correct
13 Correct 45 ms 2372 KB Output is correct
14 Correct 44 ms 2372 KB Output is correct
15 Correct 44 ms 2372 KB Output is correct
16 Correct 45 ms 2372 KB Output is correct
17 Correct 44 ms 2372 KB Output is correct
18 Correct 45 ms 2372 KB Output is correct
19 Correct 46 ms 2372 KB Output is correct
20 Correct 45 ms 2372 KB Output is correct
21 Correct 45 ms 2372 KB Output is correct
22 Correct 45 ms 2372 KB Output is correct
23 Correct 45 ms 2372 KB Output is correct
24 Correct 45 ms 2372 KB Output is correct
25 Correct 48 ms 2372 KB Output is correct
26 Correct 45 ms 2372 KB Output is correct
27 Correct 45 ms 2372 KB Output is correct
28 Correct 45 ms 2372 KB Output is correct
29 Correct 44 ms 2372 KB Output is correct
30 Correct 45 ms 2372 KB Output is correct
31 Correct 44 ms 2372 KB Output is correct
32 Correct 45 ms 2372 KB Output is correct
33 Correct 45 ms 2372 KB Output is correct
34 Correct 48 ms 2372 KB Output is correct
35 Correct 64 ms 2372 KB Output is correct
36 Correct 66 ms 2372 KB Output is correct
37 Correct 68 ms 2372 KB Output is correct
38 Correct 47 ms 2372 KB Output is correct
39 Correct 53 ms 2372 KB Output is correct
40 Correct 54 ms 2372 KB Output is correct