Submission #44664500
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define fro(i, x, y) for(int i = (x);i <= (y);i++)
#define pre(i, x, y) for(int i = (x);i >= (y);i--)
typedef long long ll;
typedef __int128 lll;
typedef unsigned int uint;
typedef pair<int, int> PII;
typedef unsigned long long ull;
const int I = 2010;
const int N = 4000010;
const int mod = 1e9 + 7;
int n, m; ll fc[N], iv[N], dp[I][I];
inline void init()
{
fc[0] = iv[0] = iv[1] = 1;
fro(i, 1, N - 10) fc[i] = fc[i - 1] * i % mod;
fro(i, 2, N - 10) iv[i] = (mod - 1ll * (mod / i) * iv[mod % i] % mod);
fro(i, 1, N - 10) iv[i] = iv[i - 1] * iv[i] % mod;
}
inline ll C(int x, int y)
{ return fc[x] * iv[y] % mod * iv[x - y] % mod; }
signed main()
{
ios::sync_with_stdio(0), cin.tie(0);
init();
cin >> n >> m, dp[0][0] = 1;
fro(i, 1, n)
{
fro(j, 0, i)
{
if(i > j) dp[i][j] += dp[i - 1][j];
if(m != 1 && j != 0)
dp[i][j] += (n - j + 1) * dp[i][j - 1] % mod * C(n * m - i - (m - 1) * (j - 1) - 1, m - 2);
dp[i][j] %= mod;
}
}
if(m == 1) cout << dp[n][0] << "\n";
else cout << dp[n][n] << "\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - Leftmost Ball |
| User | win114514 |
| Language | C++ (GCC 9.2.1) |
| Score | 1600 |
| Code Size | 1267 Byte |
| Status | AC |
| Exec Time | 205 ms |
| Memory | 88744 KiB |
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 | 130 ms | 65996 KiB |
| 0_01.txt | AC | 131 ms | 66036 KiB |
| 0_02.txt | AC | 125 ms | 66104 KiB |
| 0_03.txt | AC | 201 ms | 88560 KiB |
| 1_00.txt | AC | 126 ms | 65964 KiB |
| 1_01.txt | AC | 129 ms | 66072 KiB |
| 1_02.txt | AC | 146 ms | 88744 KiB |
| 1_03.txt | AC | 205 ms | 88716 KiB |
| 1_04.txt | AC | 187 ms | 88028 KiB |
| 1_05.txt | AC | 191 ms | 88652 KiB |
| 1_06.txt | AC | 202 ms | 88200 KiB |
| 1_07.txt | AC | 182 ms | 87376 KiB |
| 1_08.txt | AC | 197 ms | 87316 KiB |
| 1_09.txt | AC | 201 ms | 87580 KiB |
| 1_10.txt | AC | 186 ms | 87436 KiB |
| 1_11.txt | AC | 185 ms | 88140 KiB |
| 1_12.txt | AC | 129 ms | 69280 KiB |
| 1_13.txt | AC | 177 ms | 85172 KiB |
| 1_14.txt | AC | 127 ms | 66632 KiB |
| 1_15.txt | AC | 140 ms | 72456 KiB |
| 1_16.txt | AC | 152 ms | 76388 KiB |
| 1_17.txt | AC | 190 ms | 85852 KiB |
| 1_18.txt | AC | 146 ms | 67780 KiB |
| 1_19.txt | AC | 203 ms | 88404 KiB |