Skip to content

Commit 8a0b193

Browse files
committed
QOJ: Pico Park
1 parent b148397 commit 8a0b193

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

QOJ/9624.cpp

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* @file 9624.cpp
3+
* @author Macesuted ([email protected])
4+
* @date 2024-11-13
5+
*
6+
* @copyright Copyright (c) 2024
7+
*
8+
*/
9+
10+
#include <bits/stdc++.h>
11+
using namespace std;
12+
13+
#ifndef LOCAL
14+
#define endl '\n'
15+
#endif
16+
17+
bool mem1;
18+
19+
#define maxn 505
20+
#define mod 998244353
21+
22+
string a;
23+
int64_t C[maxn][maxn], f[maxn][maxn];
24+
25+
int Mod(int x) { return x >= mod ? x - mod : x; }
26+
27+
void solve(void) {
28+
int n;
29+
cin >> n >> a, a = ' ' + a;
30+
31+
f[0][0] = 1;
32+
for (int l = 1; l <= n; l++)
33+
for (int r = l, cnt[2] = {0, 0}; r <= n; r++) {
34+
if (a[r] == 'R' && cnt[0]) break;
35+
cnt[a[r] == 'R']++;
36+
37+
int64_t coef = 0;
38+
39+
if (cnt[0] && cnt[1])
40+
coef = (coef + (C[r - l - 1][cnt[0] - 1] + C[r - l - 1][cnt[1] - 1]) * (r - l)) % mod;
41+
else if ((cnt[0] && l == 1) || (cnt[1] && r == n))
42+
coef = Mod(coef + 1);
43+
if (cnt[0] >= 2) coef = (coef + C[r - l - 1][cnt[0] - 2] * (r - l)) % mod;
44+
if (cnt[1] >= 2) coef = (coef + C[r - l - 1][cnt[1] - 2] * (r - l)) % mod;
45+
46+
if (coef == 0) continue;
47+
48+
for (int k = 1; k <= r; k++) f[r][k] = (f[r][k] + f[l - 1][k - 1] * coef % mod * C[r][l - 1]) % mod;
49+
}
50+
51+
for (int i = 0; i <= n; i++) {
52+
for (int j = 0; j <= i; j++) cerr << f[i][j] << ' ';
53+
cerr << endl;
54+
}
55+
56+
for (int i = 1; i <= n; i++) cout << f[n][i] << ' ';
57+
cout << endl;
58+
59+
return;
60+
}
61+
62+
bool mem2;
63+
64+
int main() {
65+
ios::sync_with_stdio(false), cin.tie(nullptr);
66+
#ifdef LOCAL
67+
cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
68+
#endif
69+
70+
for (int i = 0; i < maxn; i++) {
71+
C[i][0] = C[i][i] = 1;
72+
for (int j = 1; j < i; j++) C[i][j] = Mod(C[i - 1][j - 1] + C[i - 1][j]);
73+
}
74+
75+
int _ = 1;
76+
while (_--) solve();
77+
78+
#ifdef LOCAL
79+
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
80+
#endif
81+
return 0;
82+
}

0 commit comments

Comments
 (0)