Submission #870522
Source Code Expand
# pragma comment(linker, "/STACK: 2000000") # include <stdio.h> # include <bits/stdc++.h> using namespace std; # define fi cin # define fo cout # define x first # define y second # define ll long long # define IOS ios_base :: sync_with_stdio(0);cin.tie(0) # define p(v) cerr << #v << " = " << v << '\n'; # define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n' # define vi vector < int > # define vll vector < ll > # define pii pair < int , int > const int mod = 1e9 + 7; int main(void) { #ifdef CF freopen("input","r",stdin); #endif // CF srand(time(0)); fo << fixed << setprecision(7); cerr << fixed << setprecision(7); int n,k; fi>>n>>k; if (k == 1) return puts("1") * 0; static int f[1 << 23]; static int c[1 << 23]; auto C = [&](auto n,auto k) { if (!(0 <= k && k <= n)) return 0; int ans = (1ll * f[n] * c[n - k]) % mod; ans = (1ll * ans * c[k]) % mod; return ans; }; auto pow = [&](auto a,auto b,auto mod) { int ans = 1; while (b) { if (b&1) ans = (1ll * ans * a) % mod; a = (1ll * a * a) % mod; b /= 2; } return ans; }; f[0] = c[0] = 1; for (int i = 1;i <= 5e6;++i) f[i] = (1ll * f[i - 1] * i) % mod; const int MAX = 5e6; c[MAX] = pow(f[MAX],mod - 2,mod); for (int i = MAX - 1;i;--i) c[i] = (1ll * c[i+1] * (i + 1)) % mod; static int dp[2005][2005]; dp[0][0] = 1; for (int i = 1;i <= n;++i) for (int j = 0;j <= i;++j) { if (j) (dp[i][j] += dp[i][j-1]) %= mod; dp[i][j] = (dp[i][j] + 1ll * C(j * k + (i - j - 1) * (k - 1) + k - 2,k - 2) * dp[i-1][j]) % mod; } fo << (1ll * dp[n][n] * f[n]) % mod << '\n'; cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Leftmost Ball |
User | reality |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 2003 Byte |
Status | AC |
Exec Time | 259 ms |
Memory | 53120 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 | 178 ms | 39296 KB |
0_01.txt | AC | 4 ms | 256 KB |
0_02.txt | AC | 166 ms | 39296 KB |
0_03.txt | AC | 259 ms | 53120 KB |
1_00.txt | AC | 4 ms | 256 KB |
1_01.txt | AC | 175 ms | 39296 KB |
1_02.txt | AC | 4 ms | 256 KB |
1_03.txt | AC | 245 ms | 53120 KB |
1_04.txt | AC | 256 ms | 52736 KB |
1_05.txt | AC | 244 ms | 53120 KB |
1_06.txt | AC | 242 ms | 52864 KB |
1_07.txt | AC | 252 ms | 52352 KB |
1_08.txt | AC | 255 ms | 52480 KB |
1_09.txt | AC | 241 ms | 52480 KB |
1_10.txt | AC | 240 ms | 52480 KB |
1_11.txt | AC | 255 ms | 52864 KB |
1_12.txt | AC | 176 ms | 41984 KB |
1_13.txt | AC | 245 ms | 51328 KB |
1_14.txt | AC | 167 ms | 39936 KB |
1_15.txt | AC | 193 ms | 44288 KB |
1_16.txt | AC | 201 ms | 46848 KB |
1_17.txt | AC | 246 ms | 51712 KB |
1_18.txt | AC | 180 ms | 40832 KB |
1_19.txt | AC | 245 ms | 52992 KB |