Submission #1033035


Source Code Expand

#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define PR pair
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define REP(i, x, y)   for(int i = (int)(x); i <= (int)(y); i++)
#define FOR(i, x, y)   for(int i = (int)(x); i <  (int)(y); i++)
#define PER(i ,x, y)  for(int i = (int)(x); i >= (int)(y); i--)
#define CH	         ch = getchar()
#define Exit(...)    printf(__VA_ARGS__), exit(0)
#define dln()        fprintf(stderr,"\n")
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef double	  db;
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI > VII;
typedef PR<int,int> PII;
typedef vector<PII> VPI;
const	int inf=2e9;
const	LL Inf=1e10;
const	int P=1e9+7;
const	int N=2005;

inline LL IN(){
	LL x = 0;
	int ch = 0, f = 0;
	for (CH; ch != -1 && (ch < 48 || ch > 57); CH) f = (ch == '-');
	for (; ch >= 48 && ch <= 57; CH) x = (x << 1) + (x << 3) + ch - '0';
	return f ? (-x) : x;
}
template<typename T> inline int chkmin(T &a, const T &b){if(b < a) return a = b, 1; return 0;}
template<typename T> inline int chkmax(T &a, const T &b){if(b > a) return a = b, 1; return 0;}

void renew(int &x, const int &y){
	x += y;
	if(x >= P) x -= P;
	if(x <  0) x += P;
}

int Pow(int x, int y, int p){
	int a = 1;
	for (; y; y >>= 1, x = (LL)x * x %p) if(y & 1) a=(LL)a * x%p;
	return a;
}

int n, k, S;
int fac[4000005], inv[4000005], f[4000005];
int DP[N << 1][N];

int main(){
	scanf("%d%d", &n, &k);
	if(k == 1){
		puts("1");
		return 0;
	}
	S = n * k;
	fac[0] = inv[0] = fac[1] = inv[1] = 1;
	REP(i, 1, 4000000) fac[i] = (LL)fac[i - 1] * i % P;
	REP(i, 2, 4000000) inv[i] = (LL)inv[P % i] * (P - P / i) % P;
	REP(i, 2, 4000000) inv[i] = (LL)inv[i - 1] * inv[i] % P;
	REP(i, k - 2, 4000000) f[i] = (LL)fac[i] * inv[k - 2] % P * inv[i - k + 2] % P;
	DP[0][0] = 1;
	//DP[i][j] 考虑[1..i],填了j个数字。
	FOR(i, 0, n + n){
		for(int j = 0; 2 * j < i; j ++) DP[i][j] = 0;
		REP(j, 0, n){
			int val = DP[i][j];
			if(!val) continue;
			renew(DP[i + 1][j], val);
			int cf = f[i + (j + 1) * (k - 2)];
			renew(DP[i + 1][j + 1], (LL)val * cf % P);
		}
	}
	int ans = DP[n + n][n];
	REP(i, 1, n) ans = (LL)ans * i % P;
	printf("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task F - Leftmost Ball
User syc19999
Language C++14 (GCC 5.4.1)
Score 1600
Code Size 2514 Byte
Status AC
Exec Time 228 ms
Memory 76544 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:66:23: 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 140 ms 47104 KB
0_01.txt AC 3 ms 256 KB
0_02.txt AC 140 ms 47104 KB
0_03.txt AC 228 ms 76544 KB
1_00.txt AC 3 ms 256 KB
1_01.txt AC 141 ms 47104 KB
1_02.txt AC 3 ms 256 KB
1_03.txt AC 228 ms 76544 KB
1_04.txt AC 223 ms 75904 KB
1_05.txt AC 225 ms 76544 KB
1_06.txt AC 225 ms 76032 KB
1_07.txt AC 221 ms 75264 KB
1_08.txt AC 219 ms 75264 KB
1_09.txt AC 221 ms 75392 KB
1_10.txt AC 227 ms 75392 KB
1_11.txt AC 224 ms 76032 KB
1_12.txt AC 153 ms 53120 KB
1_13.txt AC 212 ms 73088 KB
1_14.txt AC 143 ms 48256 KB
1_15.txt AC 165 ms 58496 KB
1_16.txt AC 181 ms 64000 KB
1_17.txt AC 214 ms 73728 KB
1_18.txt AC 150 ms 50304 KB
1_19.txt AC 223 ms 76288 KB