Submission #994849
Source Code Expand
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
ll n, m;
ll fac[200000];
ll mul_inv(ll a, ll b=MOD)
{
ll b0=b, t, q;
ll x0=0, x1=1;
if(b == 1) return 1;
while(a > 1)
{
q=a/b;
t=b, b=a%b, a=t;
t=x0, x0=x1-q*x0, x1=t;
}
if(x1 < 0) x1+=b0;
return x1;
}
ll modpow(ll x, ll y)
{
ll ans=1;
while(y)
{
if(y%2) ans*=x, ans%=MOD;
x*=x, x%=MOD;
y/=2;
}
return ans;
}
ll ncr(ll n, ll r)
{
if(n < r) return 0;
return fac[n]*mul_inv(fac[r])%MOD*mul_inv(fac[n-r])%MOD;
}
ll d[400][400];
int main()
{
ll i, j, k, l;
cin>>n>>m;
fac[0]=1;
for(i=1;i<200000;i++) fac[i]=fac[i-1]*i, fac[i]%=MOD;
ll ans=0;
d[0][1]=1;
for(i=0;i<m;i++)
{
for(j=1;j<=n;j++)
{
d[i+1][j]+=d[i][j]*j%MOD;
d[i+1][j+1]+=d[i][j]*(n-j)%MOD;
d[i+1][j]%=MOD, d[i+1][j+1]%=MOD;
}
}
for(i=n-1;i<m;i++)
{
ll t=i;
ll u=modpow(n-1, m-1-i)%MOD;
ll sum=0;
/*for(j=0;j<=n-1;j++)
{
sum+=modpow(n-j, t)*ncr(n-1, j)%MOD*(j%2==0?1:-1)%MOD;
sum%=MOD;
}
ans+=sum*u%MOD;*/
ans+=d[t][n]*u%MOD;
ans%=MOD;
}
if(ans < 0) ans+=MOD;
cout<<ans<<endl;
return 0;
}
//*/
Submission Info
Submission Time |
|
Task |
F - Road of the King |
User |
polequoll |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1749 Byte |
Status |
WA |
Exec Time |
7 ms |
Memory |
2688 KB |
Judge Result
Set Name |
sample |
all |
Score / Max Score |
0 / 0 |
0 / 1000 |
Status |
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt, sample-03.txt |
all |
sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
5 ms |
1792 KB |
01-02.txt |
AC |
5 ms |
1792 KB |
01-03.txt |
AC |
7 ms |
2688 KB |
01-04.txt |
AC |
5 ms |
1792 KB |
01-05.txt |
WA |
7 ms |
2688 KB |
01-06.txt |
WA |
7 ms |
2688 KB |
01-07.txt |
WA |
7 ms |
2688 KB |
01-08.txt |
WA |
7 ms |
2688 KB |
01-09.txt |
WA |
7 ms |
2688 KB |
01-10.txt |
AC |
7 ms |
2688 KB |
sample-01.txt |
AC |
5 ms |
1792 KB |
sample-02.txt |
WA |
7 ms |
2688 KB |
sample-03.txt |
AC |
6 ms |
2304 KB |