Submission #826334


Source Code Expand

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long LL;

LL powmod(LL a, int n){
	if(n == 0) return 1;
	if(n % 2) return (a*powmod(a,n-1)) % MOD;
	LL c = powmod(a,n/2);
	return (c*c) % MOD;
}
LL inv(LL a){
	return powmod(a,MOD-2);
}
LL dp[2100][2100];
LL fact[5000000];
LL invfact[5000000];
int main(){
	int n, k;
	cin >> n >> k;
	if(k == 1){
		cout << 1 << endl;
		return 0;
	}
	fact[0] = 1;
	for(LL i = 1; i <= 4010000; i++) fact[i] = (fact[i-1]*i) % MOD;
	invfact[4010000] = inv(fact[4010000]);
	for(LL i = 4010000-1; i >= 0; i--) invfact[i] = (invfact[i+1] * (i+1)) % MOD;

	dp[0][0] = 1;
	for(int a = 1; a <= n; a++){
		for(int b = a; b >= 0; b--){
			LL r = 0;
			if(b > 0){
				r = (a*fact[a*k-b-1]) % MOD;
				r = (r*invfact[k-2]) % MOD;
				r = (r*invfact[a*k-b-1 - (k-2)]) % MOD;
				r = (r*dp[a-1][b-1]) % MOD;
			}
			r = (r + dp[a][b+1]) % MOD;
			dp[a][b] = r;
		}
	}
	cout << dp[n][0] % MOD << endl;
}

Submission Info

Submission Time
Task F - Leftmost Ball
User ksun48
Language C++14 (GCC 5.4.1)
Score 1600
Code Size 997 Byte
Status AC
Exec Time 273 ms
Memory 85888 KB

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 168 ms 62976 KB
0_01.txt AC 4 ms 256 KB
0_02.txt AC 180 ms 62976 KB
0_03.txt AC 273 ms 85888 KB
1_00.txt AC 4 ms 256 KB
1_01.txt AC 180 ms 62848 KB
1_02.txt AC 4 ms 256 KB
1_03.txt AC 272 ms 85888 KB
1_04.txt AC 269 ms 85248 KB
1_05.txt AC 270 ms 85760 KB
1_06.txt AC 252 ms 85376 KB
1_07.txt AC 248 ms 84480 KB
1_08.txt AC 248 ms 84608 KB
1_09.txt AC 250 ms 84736 KB
1_10.txt AC 249 ms 84608 KB
1_11.txt AC 270 ms 85376 KB
1_12.txt AC 191 ms 66176 KB
1_13.txt AC 240 ms 82304 KB
1_14.txt AC 182 ms 63488 KB
1_15.txt AC 196 ms 69376 KB
1_16.txt AC 203 ms 73216 KB
1_17.txt AC 240 ms 82816 KB
1_18.txt AC 172 ms 64640 KB
1_19.txt AC 253 ms 85632 KB