Submission #27465461
Source Code Expand
#include<bits/stdc++.h>
#define P 1000000007
#define N 2005
inline void fmo(int &x){
x+=(x>>31)&P;
}
inline int fp(int x,int k=P-2){
int res=1;
for(;k;k>>=1,x=1ll*x*x%P)
if(k&1)
res=1ll*res*x%P;
return res;
}
int fac[N*N],inv[N*N],ifac[N*N];
inline void init(int x){
fac[0]=1;
for(int i=1;i<=x;i++)
fac[i]=1ll*fac[i-1]*i%P;
inv[1]=1;
for(int i=2;i<=x;i++)
fmo(inv[i]=-1ll*P/i*inv[P%i]%P);
ifac[0]=1;
for(int i=1;i<=x;i++)
ifac[i]=1ll*ifac[i-1]*inv[i]%P;
}
inline int C(int x,int y){
if(x<0||y<0||x<y)
return 0;
return 1ll*fac[x]*ifac[y]%P*ifac[x-y]%P;
}
int n,k;
int f[N][N];
int main(){
scanf("%d%d",&n,&k);
if(k==1)
return puts("1"),0;
init(n*k);
f[0][0]=1;
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++) if(f[i][j]){
if(j<n)
fmo(f[i][j+1]+=f[i][j]-P);
if(i<n&&j)
fmo(f[i+1][j-1]+=1ll*C((n-i)*k-j-1,k-2)*f[i][j]%P-P);
}
printf("%d\n",(int)(1ll*f[n][0]*fac[n]%P));
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Leftmost Ball |
| User | Y25t |
| Language | C++ (GCC 9.2.1) |
| Score | 1600 |
| Code Size | 971 Byte |
| Status | AC |
| Exec Time | 193 ms |
| Memory | 66296 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:39:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
39 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
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 | 6 ms | 3764 KiB |
| 0_01.txt | AC | 2 ms | 3688 KiB |
| 0_02.txt | AC | 3 ms | 3628 KiB |
| 0_03.txt | AC | 191 ms | 66296 KiB |
| 1_00.txt | AC | 2 ms | 3772 KiB |
| 1_01.txt | AC | 1 ms | 3672 KiB |
| 1_02.txt | AC | 2 ms | 3768 KiB |
| 1_03.txt | AC | 193 ms | 66192 KiB |
| 1_04.txt | AC | 177 ms | 62608 KiB |
| 1_05.txt | AC | 180 ms | 64260 KiB |
| 1_06.txt | AC | 182 ms | 65144 KiB |
| 1_07.txt | AC | 172 ms | 62060 KiB |
| 1_08.txt | AC | 172 ms | 62144 KiB |
| 1_09.txt | AC | 182 ms | 63864 KiB |
| 1_10.txt | AC | 176 ms | 62284 KiB |
| 1_11.txt | AC | 182 ms | 65132 KiB |
| 1_12.txt | AC | 47 ms | 18508 KiB |
| 1_13.txt | AC | 159 ms | 57208 KiB |
| 1_14.txt | AC | 10 ms | 5508 KiB |
| 1_15.txt | AC | 58 ms | 22324 KiB |
| 1_16.txt | AC | 87 ms | 34124 KiB |
| 1_17.txt | AC | 125 ms | 46736 KiB |
| 1_18.txt | AC | 11 ms | 6860 KiB |
| 1_19.txt | AC | 186 ms | 65280 KiB |