Submission #870273


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 4e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}

int n,k;
ll dp[2010][2010],F[N], inv[N];

ll nCk(int n,int k){
	if(k>n)	return 0;
	return F[n]*inv[k]%mod*inv[n-k]%mod;
}

ll f(int i,int j){
	if(i==n && j==n)	return 1;
	ll &ret = dp[i][j];
	if(ret!=-1) return ret;
	ret = 0;
	if(i!=n){
		ret = f(i+1,j);
	}
	if(i>j){
		ret = (ret+ (n-j)*f(i,j+1)%mod*nCk(n*k-i-j*(k-1)-1,k-2))%mod;
		// printf("%d %d %lld\n",n*k-i-j*(k-1)-1,k-2,nCk(n*k-i-j*(k-1)-1,k-2));
	}
	return ret;
}


int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	scanf("%d %d",&n,&k);
	if(k==1){
		printf("1\n");return 0;
	}
	FILL(dp,-1);
	F[0] = inv[0] = 1;
	REPP(i,1,N) F[i] = F[i-1]*i%mod;
	inv[N-1] = power(F[N-1],mod-2);
	for(int i=N-2;i>=1;i--){
		inv[i] = inv[i+1]*(i+1)%mod;
		assert(inv[i]*F[i]%mod==1);
	}
	printf("%lld\n",f(0,0));
	return 0;
}


Submission Info

Submission Time
Task F - Leftmost Ball
User sahilgrover
Language C++14 (GCC 5.4.1)
Score 1600
Code Size 1999 Byte
Status AC
Exec Time 393 ms
Memory 94592 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:69:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&k);
                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1600 / 1600
Status
AC × 4
AC × 24
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt
Case Name Status Exec Time Memory
0_00.txt AC 222 ms 94336 KB
0_01.txt AC 4 ms 256 KB
0_02.txt AC 226 ms 94336 KB
0_03.txt AC 393 ms 94592 KB
1_00.txt AC 4 ms 256 KB
1_01.txt AC 232 ms 94336 KB
1_02.txt AC 4 ms 256 KB
1_03.txt AC 391 ms 94592 KB
1_04.txt AC 385 ms 94592 KB
1_05.txt AC 392 ms 94592 KB
1_06.txt AC 385 ms 94592 KB
1_07.txt AC 361 ms 94592 KB
1_08.txt AC 376 ms 94592 KB
1_09.txt AC 378 ms 94592 KB
1_10.txt AC 376 ms 94592 KB
1_11.txt AC 372 ms 94592 KB
1_12.txt AC 230 ms 94336 KB
1_13.txt AC 343 ms 94464 KB
1_14.txt AC 242 ms 94336 KB
1_15.txt AC 245 ms 94464 KB
1_16.txt AC 276 ms 94464 KB
1_17.txt AC 352 ms 94464 KB
1_18.txt AC 223 ms 94336 KB
1_19.txt AC 387 ms 94592 KB