Submission #25638211
Source Code Expand
// {{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define debug(x...)
#define debug_arr(x...)
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// }}}
// clang-format off
struct Comb {
int l, mod; vector<LL> f, inv, finv;
Comb(int _n, int m = 1e9 + 7) : l(_n), mod(m) {
f.resize(l + 1), inv.resize(l + 1), finv.resize(l + 1);
inv[1] = f[0] = f[1] = finv[0] = finv[1] = 1;
for (int i = 2; i <= l; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
for (int i = 2; i <= l; ++i) f[i] = f[i - 1] * i % mod;
for (int i = 2; i <= l; ++i) finv[i] = finv[i - 1] * inv[i] % mod;
}
LL ncr(int n, int m) {
if (m < 0 || m > n) return 0;
return f[n] * finv[m] % mod * finv[n - m] % mod;
}
}; // clang-format on
const int mod = 998244353;
const int N = 410;
Comb comb(N, mod);
LL dp[N][N];
set<int> g[N];
int n, m;
LL dfs(int l, int r)
{
// debug(l, r);
if (dp[l][r] != -1) return dp[l][r];
if (l - 1 == r) return dp[l][r] = 1;
if ((r - l + 1) % 2 == 1) return dp[l][r] = 0;
LL ret = 0;
int c = (r - l + 1) / 2;
for (int p = l + 1; p <= r; p += 2)
{
if (g[l].find(p) == g[l].end()) continue;
int a = (p - 1 - (l + 1) + 1) / 2;
int b = (r - (p + 1) + 1) / 2;
assert(a + b + 1 == c);
// [l, p]; [l +1 , p -1];
// [p + 1, r]
LL cb = comb.ncr(c, b);
LL va = dfs(l + 1, p - 1);
LL vb = dfs(p + 1, r);
if (va == 0 || vb == 0) continue;
LL v = cb * vb % mod * va % mod;
ret = (ret + v) % mod;
}
// debug(l, r, ret);
return dp[l][r] = ret;
}
int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> n >> m)
{
for (int i = 1; i <= n; ++i) g[i].clear();
for (int i = 1; i <= m; ++i)
{
int a, b;
cin >> a >> b;
g[a].insert(b);
}
// for (int i = 1; i <= n; ++i) sort(all(g[i]));
clr(dp, -1);
LL ans = dfs(1, 2 * n);
cout << ans << '\n';
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
F - Make Pair |
| User |
mickeyandkaka |
| Language |
C++ (GCC 9.2.1) |
| Score |
500 |
| Code Size |
2521 Byte |
| Status |
AC |
| Exec Time |
167 ms |
| Memory |
8540 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt, example_01.txt, example_02.txt |
| All |
example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
5 ms |
4836 KiB |
| example_01.txt |
AC |
3 ms |
4892 KiB |
| example_02.txt |
AC |
4 ms |
4948 KiB |
| hand_00.txt |
AC |
167 ms |
8540 KiB |
| hand_01.txt |
AC |
127 ms |
6728 KiB |
| hand_02.txt |
AC |
4 ms |
4832 KiB |
| hand_03.txt |
AC |
4 ms |
4860 KiB |
| hand_04.txt |
AC |
4 ms |
4968 KiB |
| hand_05.txt |
AC |
5 ms |
4832 KiB |
| hand_06.txt |
AC |
4 ms |
4948 KiB |
| random_00.txt |
AC |
3 ms |
4848 KiB |
| random_01.txt |
AC |
5 ms |
4844 KiB |
| random_02.txt |
AC |
5 ms |
4984 KiB |
| random_03.txt |
AC |
123 ms |
6616 KiB |
| random_04.txt |
AC |
140 ms |
8208 KiB |
| random_05.txt |
AC |
6 ms |
5064 KiB |
| random_06.txt |
AC |
112 ms |
6252 KiB |
| random_07.txt |
AC |
145 ms |
7716 KiB |
| random_08.txt |
AC |
160 ms |
7812 KiB |
| random_09.txt |
AC |
102 ms |
5820 KiB |
| random_10.txt |
AC |
6 ms |
4900 KiB |
| random_11.txt |
AC |
135 ms |
6708 KiB |
| random_12.txt |
AC |
71 ms |
5432 KiB |
| random_13.txt |
AC |
107 ms |
6004 KiB |
| random_14.txt |
AC |
107 ms |
5940 KiB |
| random_15.txt |
AC |
4 ms |
4904 KiB |
| random_16.txt |
AC |
42 ms |
5308 KiB |
| random_17.txt |
AC |
35 ms |
5300 KiB |