# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58895 | TadijaSebez | Asceticism (JOI18_asceticism) | C++11 | 6 ms | 1912 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define ll long long
const int N=200050;
const int mod=1000000007;
int F[N],I[N];
int pow(int x, int k){ int ret=1;for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ret=(ll)ret*x%mod;return ret;}
int get(int n, int k){ return (ll)F[n]*I[k]%mod*I[n-k]%mod;}
int calc(int n, int k)
{
if(k>n) return 0;
int ret=0;
for(int i=0;i<=k;i++)
{
int add=(ll)get(i,n+1)*pow(k+1-i,n)%mod;
if(i&1) ret=(ret-add+mod)%mod;
else ret=(ret+add)%mod;
}
return ret;
}
int main()
{
int n,k,x,i,sum=0;
F[0]=1;for(i=1;i<N;i++) F[i]=(ll)F[i-1]*i%mod;
I[N-1]=pow(F[N-1],mod-2);for(i=N-2;i>=0;i--) I[i]=(ll)I[i+1]*(i+1)%mod;
scanf("%i %i",&n,&k);
printf("%i\n",calc(n,k-1));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |