namespace io { const int SI = 1 << 21 | 1; char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100]; int f, t; #define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++) inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; } inline void pc(char x) { *OS++ = x; if (OS == OT) flush(); } template<class I> inline void rd(I &x) { for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1; for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc()); x *= f; } inline void rds(char *s, int &x) { for (c = gc(); c < 33 || c > 126; c = gc()); for (x = 0; c >= 33 && c <= 126; s[++x] = c, c = gc()); s[x+1] = '\0'; } template<class I> inline void print(I x, char k = '\n') { if (!x) pc('0'); if (x < 0) pc('-'), x = -x; while (x) ch[++t] = x % 10 + '0', x /= 10; while (t) pc(ch[t--]); pc(k); } struct Flush { ~Flush() { flush(); } } flusher; } using io::rd; using io::rds; using io::print;
namespace Rd { inline bool gt() { int a = rand(), b = rand(); while (a == b) a = rand(), b = rand(); return a < b; } template<class I> inline I Rand(I k) { if (!k) return 0; I w = 1; while (w < k) w <<= 1; while (w >= k) { I o = 1, x = 0; while (o < k) o <<= 1, x = (x << 1) + gt(); w = x; } return w; } template<class I> inline I rdm(I l, I r) { return l + Rand(r - l + 1); } template<class I> inline void rdms(I *a, int n) { pair< int, I > p[n+1]; map< int, bool > m; m.clear(); for (int i = 1; i <= n; i++) { int o = rdm(0, 1000000000); while (m[o]) o = rdm(0, 1000000000); m[o] = 1; p[i] = mp(o, a[i]); } sort(p + 1, p + n + 1); for (int i = 1; i <= n; i++) a[i] = p[i].se; } } using Rd::gt; using Rd::rdm; using Rd::rdms;
namespace kc { template<class I> inline I Min(I x, I y) { return x < y ? x : y; } template<class I> inline I Max(I x, I y) { return x > y ? x : y; } template<class I> inline void Swp(I &x, I &y) { x ^= y ^= x ^= y; } template<class I> inline I Abs(I x) { return x >= 0 ? x : -x; } } using kc::Min; using kc::Max; using kc::Swp; using kc::Abs;
namespace Md { const int P = 998244353; inline int Add(int a, int b) { return a + b >= P ? a + b - P : a + b; } inline int Sub(int a, int b) { return a - b < 0 ? a - b + P : a - b; } inline int Mul(int a, int b) { return 1ll * a * b % P; } inline int ksm(int a, ll b = P - 2) { b %= P - 1; int c = 1; while (b) { if (b & 1) c = Mul(c, a); a = Mul(a, a), b >>= 1; } return c; } inline int Div(int a, int b) { return 1ll * a * ksm(b) % P; } } using Md::Add; using Md::Sub; using Md::Mul; using Md::Div; using Md::ksm;
const int N = 2e3 + 7, M = 27; int n, ans; char s[N];
struct Mat { int a[M][M]; inline Mat() { memset(a, 0, sizeof(a)); } inline friend Mat operator * (Mat a, Mat b) { Mat c = Mat(); for (int i = 0; i < M; i++) for (int k = 0; k < M; k++) for (int j = 0; j < M; j++) c.a[i][j] = Add(c.a[i][j], Mul(a.a[i][k], b.a[k][j])); return c; } } x, a[M];
int main() { rd(n), rds(s, n), x = Mat(); for (int i = 0; i < M; i++) x.a[i][i] = 1; for (int i = 0; i < M - 1; i++) for (int j = 0; j < M; j++) if (i ^ j) a[i].a[j][j] = 1; else for (int k = 0; k < M; k++) a[i].a[i][k] = 1; for (int i = n; i; i--) x = x * a[s[i]-'a'] * x; for (int i = 0; i < M - 1; i++) ans = Add(ans, x.a[i][26]); print(ans); return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 998244353; inline void reduce(int &x) { x += x >> 31 & mod; } inline int mul(int x, int y) { return 1ll * x * y % mod; } //ruogu_alter const int N = 1005; int g[N][N], f[N][N], n, m; // int main() { n = getint(); m = getint(); int val = 1; for (int i = 2; i * i <= m; i++) { if (m % (i * i)) continue; while (m % (i * i) == 0) m /= (i * i), val *= i; } m = val; f[0][0] = 1; for (int i = 0; i <= min(35, m); i++) { for (int j = 1; j <= n; j++) { for (int k = i; k <= m; k++) { reduce(f[j][k] += f[j - 1][k - i] - mod); } } } g[0][0] = 1; for (int i = 36; i <= m; i++) { for (int j = 1; j <= min(n, 35); j++) { for (int k = i; k <= m; k++) { reduce(g[j][k] += g[j - 1][k - i] - mod); } } } int res = 0; rep(i, n + 1) rep(j, m + 1) reduce(res += mul(f[i][j], g[n - i][m - j]) - mod); cout << res << endl; return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair <int, int> #define iiii pair <int, pii > #define mp make_pair #define INF 1000000000 #define rep(i, x) for(int (i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 998244353; inline void reduce(int &x) { x += x >> 31 & mod; } inline int mul(int x, int y) { return 1ll * x * y % mod; } //ruogu_alter const int N = 5e4 + 5; int n, a[N], f[2][N]; // int modpow(int x, int y) { int ans = 1; while (y) { if (y & 1) ans = mul(ans, x); x = mul(x, x); y >>= 1; } return ans; } int main() { n = getint(); rep(i, n) a[i] = getint(); f[0][0] = 1; int sum = 0; rep(ii, n) { int x = getint(); sum += x; for (int j = sum; j >= x; --j) { reduce(f[0][j] += f[a[ii]][j - x] - mod); reduce(f[1][j] += f[a[ii] ^ 1][j - x] - mod); } } int res = 0; for (int i = 1; i <= sum; i++) { reduce(res += mul(modpow(i, mod - 2), f[1][i]) - mod); } cout << mul(sum, res) << endl; return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair<int, int> #define iiii pair<int, pii> #define mp make_pair #define INF 1000000000 #define MOD 1000000007 #define rep(i, x) for (int(i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; // ruogu const int N = 1e5 + 5; int n, m; vector<int> G[N]; int cnt, dep[N], in[N], out[N], re[N], id[N], to[20][N << 1], lb[N << 1]; int rt[N], sum[N * 40], ls[N * 40], rs[N * 40], mx[N * 40], mn[N * 40], dat[N * 40]; vector<int> vs, Q[N][2]; ll res; //
void init(int x, int p, int d) { dep[x] = d; in[x] = ++cnt; vs.push_back(x); id[x] = vs.size() - 1; rep(i, G[x].size()) { int to = G[x][i]; if (to == p) continue; init(to, x, d + 1); vs.push_back(x); } out[x] = cnt - 1; --in[x]; re[in[x]] = x; }
inline int lca(int x, int y) { x = id[x]; y = id[y]; if (x > y) swap(x, y); int len = y - x + 1, L = lb[len]; int lx = to[L][x], rx = to[L][y - (1 << L) + 1]; return dep[lx] < dep[rx] ? lx : rx; }