Submission #312788

# Submission time Handle Problem Language Result Execution time Memory
312788 2020-10-14T11:23:25 Z YJU Asceticism (JOI18_asceticism) C++14
100 / 100
80 ms 6680 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=4e5+5;
const ll K=350;
const ld pi=3.14159265359;
const ll INF=(1LL<<40);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

ll n,m,fac[N],rfac[N];

ll C(ll a,ll b){
	return fac[a]*rfac[b]%MOD*rfac[a-b]%MOD;
}

ll po(ll base,ll ti){
	ll res=1;
	for(;ti;ti>>=1,base=base*base%MOD){
		if(ti&1)res=res*base%MOD;
	}
	return res;
}

ll cal(ll k){
	ll tmp=0;
	for(int i=0,o=1;i<k;i++,o=-o)tmp=(tmp+1LL*o*C(n,i)*po(k-i,n))%MOD;
	return (tmp+MOD)%MOD;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	fac[0]=rfac[0]=1;
	REP1(i,N-1)fac[i]=i*fac[i-1]%MOD,rfac[i]=rfac[i-1]*po(i,MOD-2)%MOD;
	ll ans=cal(m)-cal(m-1);
	cout<<(ans%MOD+MOD)%MOD<<"\n";
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 64 ms 6648 KB Output is correct
2 Correct 66 ms 6648 KB Output is correct
3 Correct 64 ms 6524 KB Output is correct
4 Correct 64 ms 6520 KB Output is correct
5 Correct 64 ms 6652 KB Output is correct
6 Correct 64 ms 6652 KB Output is correct
7 Correct 64 ms 6520 KB Output is correct
8 Correct 64 ms 6680 KB Output is correct
9 Correct 64 ms 6648 KB Output is correct
10 Correct 64 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 6648 KB Output is correct
2 Correct 66 ms 6648 KB Output is correct
3 Correct 64 ms 6524 KB Output is correct
4 Correct 64 ms 6520 KB Output is correct
5 Correct 64 ms 6652 KB Output is correct
6 Correct 64 ms 6652 KB Output is correct
7 Correct 64 ms 6520 KB Output is correct
8 Correct 64 ms 6680 KB Output is correct
9 Correct 64 ms 6648 KB Output is correct
10 Correct 64 ms 6648 KB Output is correct
11 Correct 64 ms 6648 KB Output is correct
12 Correct 65 ms 6576 KB Output is correct
13 Correct 66 ms 6648 KB Output is correct
14 Correct 65 ms 6520 KB Output is correct
15 Correct 64 ms 6648 KB Output is correct
16 Correct 65 ms 6648 KB Output is correct
17 Correct 64 ms 6648 KB Output is correct
18 Correct 64 ms 6520 KB Output is correct
19 Correct 64 ms 6520 KB Output is correct
20 Correct 65 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 6648 KB Output is correct
2 Correct 66 ms 6648 KB Output is correct
3 Correct 64 ms 6524 KB Output is correct
4 Correct 64 ms 6520 KB Output is correct
5 Correct 64 ms 6652 KB Output is correct
6 Correct 64 ms 6652 KB Output is correct
7 Correct 64 ms 6520 KB Output is correct
8 Correct 64 ms 6680 KB Output is correct
9 Correct 64 ms 6648 KB Output is correct
10 Correct 64 ms 6648 KB Output is correct
11 Correct 64 ms 6648 KB Output is correct
12 Correct 65 ms 6576 KB Output is correct
13 Correct 66 ms 6648 KB Output is correct
14 Correct 65 ms 6520 KB Output is correct
15 Correct 64 ms 6648 KB Output is correct
16 Correct 65 ms 6648 KB Output is correct
17 Correct 64 ms 6648 KB Output is correct
18 Correct 64 ms 6520 KB Output is correct
19 Correct 64 ms 6520 KB Output is correct
20 Correct 65 ms 6648 KB Output is correct
21 Correct 65 ms 6620 KB Output is correct
22 Correct 65 ms 6524 KB Output is correct
23 Correct 64 ms 6520 KB Output is correct
24 Correct 64 ms 6648 KB Output is correct
25 Correct 64 ms 6520 KB Output is correct
26 Correct 65 ms 6520 KB Output is correct
27 Correct 64 ms 6520 KB Output is correct
28 Correct 66 ms 6524 KB Output is correct
29 Correct 65 ms 6648 KB Output is correct
30 Correct 66 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 6648 KB Output is correct
2 Correct 66 ms 6648 KB Output is correct
3 Correct 64 ms 6524 KB Output is correct
4 Correct 64 ms 6520 KB Output is correct
5 Correct 64 ms 6652 KB Output is correct
6 Correct 64 ms 6652 KB Output is correct
7 Correct 64 ms 6520 KB Output is correct
8 Correct 64 ms 6680 KB Output is correct
9 Correct 64 ms 6648 KB Output is correct
10 Correct 64 ms 6648 KB Output is correct
11 Correct 64 ms 6648 KB Output is correct
12 Correct 65 ms 6576 KB Output is correct
13 Correct 66 ms 6648 KB Output is correct
14 Correct 65 ms 6520 KB Output is correct
15 Correct 64 ms 6648 KB Output is correct
16 Correct 65 ms 6648 KB Output is correct
17 Correct 64 ms 6648 KB Output is correct
18 Correct 64 ms 6520 KB Output is correct
19 Correct 64 ms 6520 KB Output is correct
20 Correct 65 ms 6648 KB Output is correct
21 Correct 65 ms 6620 KB Output is correct
22 Correct 65 ms 6524 KB Output is correct
23 Correct 64 ms 6520 KB Output is correct
24 Correct 64 ms 6648 KB Output is correct
25 Correct 64 ms 6520 KB Output is correct
26 Correct 65 ms 6520 KB Output is correct
27 Correct 64 ms 6520 KB Output is correct
28 Correct 66 ms 6524 KB Output is correct
29 Correct 65 ms 6648 KB Output is correct
30 Correct 66 ms 6648 KB Output is correct
31 Correct 64 ms 6520 KB Output is correct
32 Correct 64 ms 6520 KB Output is correct
33 Correct 65 ms 6520 KB Output is correct
34 Correct 67 ms 6604 KB Output is correct
35 Correct 78 ms 6520 KB Output is correct
36 Correct 80 ms 6520 KB Output is correct
37 Correct 80 ms 6648 KB Output is correct
38 Correct 66 ms 6520 KB Output is correct
39 Correct 71 ms 6648 KB Output is correct
40 Correct 72 ms 6608 KB Output is correct