QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#183563 | #4375. String | jrjyy | AC ✓ | 80ms | 13916kb | C++20 | 3.4kb | 2023-09-19 17:16:18 | 2023-09-19 17:16:19 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
template <typename T> constexpr T power(T a, i64 b) {
T c{1}; for (; b; b /= 2, a *= a) if (b & 1) c *= a;
return c;
}
template <int P> struct MInt {
int x;
constexpr MInt() : x{} {}
constexpr MInt(i64 x_) : x{norm(x_ % getMod())} {}
static int Mod;
constexpr static int getMod() { return P > 0 ? P : Mod; }
constexpr static void setMod(int Mod_) { Mod = Mod_; }
constexpr int up(int x) const {
if (x < 0) x += getMod();
return x;
}
constexpr int down(int x) const {
if (x >= getMod()) x -= getMod();
return x;
}
constexpr int norm(int x) const {
return up(down(x));
}
constexpr int val() const { return x; }
explicit constexpr operator int() const { return x; }
constexpr MInt operator-() const {
MInt res; res.x = norm(getMod() - x); return res;
}
constexpr MInt inv() const {
assert(x != 0);
return power(*this, getMod() - 2);
}
constexpr MInt &operator+=(MInt rhs) & { return x = down(x + rhs.x), *this; }
constexpr MInt &operator-=(MInt rhs) & { return x = up(x - rhs.x), *this; }
constexpr MInt &operator*=(MInt rhs) & { return x = 1ll * x * rhs.x % getMod(), *this; }
constexpr MInt &operator/=(MInt rhs) & { return *this *= rhs.inv(); }
friend constexpr MInt operator+(MInt lhs, MInt rhs) { return lhs += rhs; }
friend constexpr MInt operator-(MInt lhs, MInt rhs) { return lhs -= rhs; }
friend constexpr MInt operator*(MInt lhs, MInt rhs) { return lhs *= rhs; }
friend constexpr MInt operator/(MInt lhs, MInt rhs) { return lhs /= rhs; }
friend constexpr bool operator==(MInt lhs, MInt rhs) { return lhs.val() == rhs.val(); }
friend constexpr bool operator!=(MInt lhs, MInt rhs) { return lhs.val() != rhs.val(); }
friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
i64 x = 0; is >> x, a = MInt(x); return is;
}
friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) {
return os << a.val();
}
};
template <int P> int MInt<P>::Mod = P;
template <> int MInt<0>::Mod = 998244353;
template <int V, int P> constexpr MInt<P> CInv = MInt<P>(V).inv();
constexpr int P = 998244353;
using Z = MInt<P>;
void solve() {
std::string s;
std::cin >> s;
int n = int(s.size());
int k;
std::cin >> k;
std::vector<int> z(n);
z[0] = n;
for (int i = 1, l = 0, r = 0; i < n; ++i) {
z[i] = std::max(std::min(r - i, z[i - l]), 0);
while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
++z[i];
}
if (i + z[i] > r) {
l = i;
r = i + z[i];
}
}
std::vector<int> a(n + 1);
for (int i = 0; i < n; ++i) {
if (z[i] >= i && 2 * i + k <= n) {
a[2 * i + k] += 1;
int x = std::min(z[i] - i, n - 2 * i) / k * k + 2 * i;
if (x + k <= n) {
a[x + k] -= 1;
}
}
}
Z ans = 1;
for (int i = 1; i <= n; ++i) {
if (i + k <= n) {
a[i + k] += a[i];
}
ans *= a[i] + 1;
}
std::cout << ans << "\n";
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 80ms
memory: 13916kb
input:
10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...
output:
811844748 106557744 583082277 750875845 539889742 198008691 286657978 344446711 612851418 36100066
result:
ok 10 lines