Submission #2123554
Source Code Expand
#include <bits/stdc++.h> #define C(n,m) (1ll*ml[n]*ny[m]%mo*ny[(n)-(m)]%mo) #define cal(a,b) ((a+=b)%=mo) using namespace std; const int mo=1e9+7; int f[2050][2050],ml[4000050],ny[4000050]; int fap(int a,int b){ int s=1; while(b){ if (b&1) s=1ll*a*s%mo; b>>=1,a=1ll*a*a%mo; } return s; } int main(){ int n,k; cin>>n>>k; if (k==1) return puts("1"),0; ml[0]=ny[0]=1; for (int i=1; i<=n*k; ++i) ml[i]=1ll*ml[i-1]*i%mo; ny[n*k]=fap(ml[n*k],mo-2); for (int i=n*k-1; i; --i) ny[i]=1ll*(i+1)*ny[i+1]%mo; f[0][0]=1; for (int i=0; i<n; ++i) for (int j=0; j<=i; ++j){ cal(f[i+1][j],1ll*f[i][j]*C((i+1)*(k-1)+j-1,k-2)%mo); if (j!=i) cal(f[i][j+1],f[i][j]); } for (int i=0; i<n; ++i) cal(f[n][i+1],f[n][i]); for (int i=1; i<=n; ++i) f[n][n]=1ll*f[n][n]*i%mo; cout<<f[n][n]; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Leftmost Ball |
User | Thefinal |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 866 Byte |
Status | AC |
Exec Time | 80 ms |
Memory | 47488 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1600 / 1600 | ||||
Status |
|
|
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 | 2 ms | 4352 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 2 ms | 4352 KB |
0_03.txt | AC | 80 ms | 47488 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 2 ms | 4352 KB |
1_02.txt | AC | 1 ms | 256 KB |
1_03.txt | AC | 79 ms | 47488 KB |
1_04.txt | AC | 75 ms | 47360 KB |
1_05.txt | AC | 77 ms | 47488 KB |
1_06.txt | AC | 78 ms | 47360 KB |
1_07.txt | AC | 74 ms | 47360 KB |
1_08.txt | AC | 74 ms | 47360 KB |
1_09.txt | AC | 76 ms | 47360 KB |
1_10.txt | AC | 74 ms | 47360 KB |
1_11.txt | AC | 78 ms | 47360 KB |
1_12.txt | AC | 17 ms | 16640 KB |
1_13.txt | AC | 67 ms | 47360 KB |
1_14.txt | AC | 3 ms | 4736 KB |
1_15.txt | AC | 21 ms | 18688 KB |
1_16.txt | AC | 36 ms | 28928 KB |
1_17.txt | AC | 56 ms | 39168 KB |
1_18.txt | AC | 5 ms | 6912 KB |
1_19.txt | AC | 78 ms | 47360 KB |