Submission #8521546


Source Code Expand

Copy
#include<bits/stdc++.h>
#define MAXN 2005
#define MAXM 4000005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int N,K,fact[MAXM],invf[MAXM];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
int comb(int n,int k)
{
    if(n<k) return 0;
    return 1LL*fact[n]*invf[k]%MOD*invf[n-k]%MOD;
}
int dp[MAXN][MAXN];
int main()
{
    fact[0]=invf[0]=1;
    for(int i=1;i<=4000000;i++) fact[i]=1LL*fact[i-1]*i%MOD;
    invf[4000000]=pow_mod(fact[4000000],MOD-2);
    for(int i=3999999;i>=1;i--) invf[i]=1LL*invf[i+1]*(i+1)%MOD;
    scanf("%d%d",&N,&K);
    if(K==1) {puts("1"); return 0;}
    dp[0][0]=1;
    for(int i=0;i<=N;i++)
        for(int j=0;j<=N;j++)
        {
            if(i<N) add(dp[i+1][j],dp[i][j]);
            if(j<i) add(dp[i][j+1],1LL*dp[i][j]*comb(N-i+(N-j-1)*(K-1)+K-2,K-2)%MOD);
        }
    printf("%d\n",1LL*dp[N][N]*fact[N]%MOD);
    return 0;
}

Submission Info

Submission Time
Task F - Leftmost Ball
User Roundgod
Language C++14 (GCC 5.4.1)
Score 1600
Code Size 1210 Byte
Status AC
Exec Time 110 ms
Memory 47232 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:46:43: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
     printf("%d\n",1LL*dp[N][N]*fact[N]%MOD);
                                           ^
./Main.cpp:37:24: 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 54 ms 32896 KB
0_01.txt AC 54 ms 32896 KB
0_02.txt AC 54 ms 32896 KB
0_03.txt AC 110 ms 47232 KB
1_00.txt AC 54 ms 32896 KB
1_01.txt AC 54 ms 32896 KB
1_02.txt AC 54 ms 32896 KB
1_03.txt AC 109 ms 47232 KB
1_04.txt AC 104 ms 47232 KB
1_05.txt AC 106 ms 47232 KB
1_06.txt AC 105 ms 47232 KB
1_07.txt AC 98 ms 47232 KB
1_08.txt AC 99 ms 47232 KB
1_09.txt AC 98 ms 47232 KB
1_10.txt AC 104 ms 47232 KB
1_11.txt AC 101 ms 47232 KB
1_12.txt AC 58 ms 38528 KB
1_13.txt AC 97 ms 47232 KB
1_14.txt AC 54 ms 33536 KB
1_15.txt AC 64 ms 40960 KB
1_16.txt AC 72 ms 43136 KB
1_17.txt AC 92 ms 47232 KB
1_18.txt AC 56 ms 36352 KB
1_19.txt AC 107 ms 47232 KB