QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#292886 | #6333. Festivals in JOI Kingdom 2 | Max_s_xaM | 51 | 119ms | 13244kb | C++14 | 3.6kb | 2023-12-28 16:10:33 | 2023-12-28 16:10:34 |
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 = 3e3 + 10, MAXM = 4e4 + 10;
int n, mod;
ll f[MAXN][MAXN], g[MAXN][MAXN];
ll fac[MAXM], inv[MAXM];
inline ll C(int n, int m) {return fac[n] * inv[n - m] % mod * inv[m] % mod;}
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n), Read(mod);
fac[0] = fac[1] = inv[0] = inv[1] = 1;
for (int i = 2; i < MAXM; i++) fac[i] = fac[i - 1] * i % mod, inv[i] = (mod - mod / i) * inv[mod % i] % mod;
for (int i = 2; i < MAXM; i++) inv[i] = inv[i - 1] * inv[i] % mod;
f[n][0] = 1;
for (int i = n; i >= 1; i--)
{
for (int j = 1; j <= i; j++) g[i][j] = (g[i][j] + g[i][j - 1]) % mod;
for (int j = 0; j <= i; j++) f[i][j] = (f[i][j] + g[i][j] + mod) % mod;
f[i - 1][0] = (f[i - 1][0] + f[i][0]) % mod;
for (int j = 0; j <= i; j++)
{
for (int x = max(2, j + 1); x <= i; x++)
{
if (x <= 2 * i - 2) f[i - x][0] = (f[i - x][0] + f[i][j] * C(2 * i - x - 1, x - 1) % mod * fac[x - 1]) % mod;
int r = 2 * i - 2 - x;
if (r < 0) continue;
// for (int y = 0; y <= r; y++)
// f[i - x][y] = (f[i - x][y] + f[i][j] * C(2 * i - x - 1, x - 2) % mod * fac[x - 1]) % mod;
g[i - x][0] = (g[i - x][0] + f[i][j] * C(2 * i - x - 1, x - 2) % mod * fac[x - 1]) % mod;
if (r < 2 * n) g[i - x][r + 1] = (g[i - x][r + 1] - f[i][j] * C(2 * i - x - 1, x - 2) % mod * fac[x - 1]) % mod;
}
}
}
f[0][0] = (f[0][0] + g[0][0] + mod) % mod;
ll ans = 1;
for (int i = 3; i <= 2 * n; i += 2) ans = ans * i % mod;
cout << (ans - f[0][0] + mod) % mod << "\n";
return 0;
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 8180kb
input:
1 194903119
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 2ms
memory: 8144kb
input:
2 933234047
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9876kb
input:
3 277793111
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 3ms
memory: 10200kb
input:
4 355321177
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: 0
Accepted
time: 2ms
memory: 8196kb
input:
5 306636893
output:
358
result:
ok 1 number(s): "358"
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 2ms
memory: 8156kb
input:
8 361605653
output:
1236922
result:
ok 1 number(s): "1236922"
Test #7:
score: 0
Accepted
time: 0ms
memory: 9708kb
input:
8 995512643
output:
1236922
result:
ok 1 number(s): "1236922"
Test #8:
score: 0
Accepted
time: 2ms
memory: 8220kb
input:
8 101102801
output:
1236922
result:
ok 1 number(s): "1236922"
Test #9:
score: 0
Accepted
time: 0ms
memory: 8204kb
input:
6 458322727
output:
4894
result:
ok 1 number(s): "4894"
Test #10:
score: 0
Accepted
time: 2ms
memory: 8212kb
input:
7 721691819
output:
73884
result:
ok 1 number(s): "73884"
Test #11:
score: 0
Accepted
time: 0ms
memory: 8332kb
input:
7 370629137
output:
73884
result:
ok 1 number(s): "73884"
Subtask #3:
score: 27
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #12:
score: 27
Accepted
time: 0ms
memory: 8344kb
input:
30 779092367
output:
686412377
result:
ok 1 number(s): "686412377"
Test #13:
score: 0
Accepted
time: 0ms
memory: 8404kb
input:
29 963995171
output:
128570082
result:
ok 1 number(s): "128570082"
Test #14:
score: 0
Accepted
time: 2ms
memory: 8280kb
input:
18 666092701
output:
185922458
result:
ok 1 number(s): "185922458"
Test #15:
score: 0
Accepted
time: 0ms
memory: 9928kb
input:
14 671243719
output:
623913899
result:
ok 1 number(s): "623913899"
Subtask #4:
score: 14
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 14
Accepted
time: 119ms
memory: 13244kb
input:
300 463478027
output:
89265245
result:
ok 1 number(s): "89265245"
Test #17:
score: 0
Accepted
time: 110ms
memory: 11520kb
input:
296 567610679
output:
406342763
result:
ok 1 number(s): "406342763"
Test #18:
score: 0
Accepted
time: 119ms
memory: 12968kb
input:
297 609090359
output:
128986577
result:
ok 1 number(s): "128986577"
Test #19:
score: 0
Accepted
time: 3ms
memory: 10112kb
input:
48 759569383
output:
635573072
result:
ok 1 number(s): "635573072"
Test #20:
score: 0
Accepted
time: 3ms
memory: 8836kb
input:
99 298873033
output:
285340078
result:
ok 1 number(s): "285340078"
Subtask #5:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 0
Time Limit Exceeded
input:
3000 752129633
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
0%