QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#422330 | #1064. 移动金币 | Max_s_xaM | 100 ✓ | 25ms | 17492kb | C++14 | 3.0kb | 2024-05-27 11:57:02 | 2024-05-27 11:57:03 |
Judging History
answer
#include <iostream>
#include <algorithm>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 15e4 + 10, mod = 1e9 + 9;
ll inv[MAXN], fac[MAXN];
inline ll C(int n, int m) {return fac[n] * inv[m] % mod * inv[n - m] % mod;}
int n, m;
ll f[20][MAXN];
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
inv[0] = inv[1] = fac[0] = fac[1] = 1;
for (int i = 2; i < MAXN; i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod, fac[i] = fac[i - 1] * i % mod;
for (int i = 2; i < MAXN; i++) inv[i] = inv[i - 1] * inv[i] % mod;
Read(n), Read(m);
int t = (m + 1) / 2, top;
f[0][0] = 1;
for (int i = 0, p; (1 << i) <= n; i++)
{
int ed = ((1 << i) - 1) * t;
for (int s = 0; s <= n && s <= ed; s++)
for (int j = 0; j <= t && (p = s + j * (1 << i)) <= n; j += 2)
{
f[i + 1][p] = (f[i + 1][p] + f[i][s] * C(t, j)) % mod;
}
top = i + 1;
}
// for (int i = 0; i <= n - m; i++) cout << f[top][i] << ' '; cout << '\n';
t = m / 2 + 1;
ll ans = 0;
for (int i = 0; i <= n - m; i++)
ans = (ans + f[top][i] * C(n - m - i + t - 1, t - 1)) % mod;
cout << (C(n, m) - ans + mod) % mod << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 50
Accepted
Test #1:
score: 50
Accepted
time: 2ms
memory: 7788kb
input:
242 49
output:
328585486
result:
ok single line: '328585486'
Test #2:
score: 0
Accepted
time: 2ms
memory: 7840kb
input:
242 47
output:
219114925
result:
ok single line: '219114925'
Test #3:
score: 0
Accepted
time: 0ms
memory: 7764kb
input:
243 50
output:
45372101
result:
ok single line: '45372101'
Test #4:
score: 0
Accepted
time: 0ms
memory: 7864kb
input:
243 47
output:
650410655
result:
ok single line: '650410655'
Test #5:
score: 0
Accepted
time: 0ms
memory: 7800kb
input:
244 47
output:
179262409
result:
ok single line: '179262409'
Test #6:
score: 0
Accepted
time: 2ms
memory: 7720kb
input:
245 50
output:
238336251
result:
ok single line: '238336251'
Test #7:
score: 0
Accepted
time: 2ms
memory: 7788kb
input:
245 48
output:
596598396
result:
ok single line: '596598396'
Test #8:
score: 0
Accepted
time: 0ms
memory: 7784kb
input:
246 46
output:
989539157
result:
ok single line: '989539157'
Test #9:
score: 0
Accepted
time: 0ms
memory: 7728kb
input:
246 46
output:
989539157
result:
ok single line: '989539157'
Test #10:
score: 0
Accepted
time: 3ms
memory: 9884kb
input:
240 50
output:
876085357
result:
ok single line: '876085357'
Subtask #2:
score: 50
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 50
Accepted
time: 21ms
memory: 16012kb
input:
142791 49
output:
83586215
result:
ok single line: '83586215'
Test #12:
score: 0
Accepted
time: 24ms
memory: 16092kb
input:
145417 47
output:
461460544
result:
ok single line: '461460544'
Test #13:
score: 0
Accepted
time: 22ms
memory: 15884kb
input:
148042 50
output:
990066474
result:
ok single line: '990066474'
Test #14:
score: 0
Accepted
time: 24ms
memory: 17104kb
input:
135668 50
output:
849717347
result:
ok single line: '849717347'
Test #15:
score: 0
Accepted
time: 23ms
memory: 15648kb
input:
138293 48
output:
605810507
result:
ok single line: '605810507'
Test #16:
score: 0
Accepted
time: 22ms
memory: 15852kb
input:
140919 46
output:
842694042
result:
ok single line: '842694042'
Test #17:
score: 0
Accepted
time: 25ms
memory: 16112kb
input:
143544 49
output:
806787086
result:
ok single line: '806787086'
Test #18:
score: 0
Accepted
time: 16ms
memory: 17492kb
input:
146170 49
output:
792539725
result:
ok single line: '792539725'
Test #19:
score: 0
Accepted
time: 25ms
memory: 16196kb
input:
148795 47
output:
445621354
result:
ok single line: '445621354'
Test #20:
score: 0
Accepted
time: 19ms
memory: 15820kb
input:
137925 48
output:
562018157
result:
ok single line: '562018157'