Submission #808681

#TimeUsernameProblemLanguageResultExecution timeMemory
808681starplatAsceticism (JOI18_asceticism)C++14
100 / 100
16 ms2648 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...