QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#91249 | #4375. String | Tobo# | AC ✓ | 492ms | 165776kb | C++20 | 1.5kb | 2023-03-27 21:30:18 | 2023-03-27 21:30:22 |
Judging History
answer
#include <bits/stdc++.h>
#define N 1000005
using i64 = long long;
using namespace std;
string s;
int n, k, nxt[N], ans[N], kmod[N];
vector<int> adj[N], trash;
deque<int> node;
void dfs(int cur, int fa)
{
while (!node.empty() && node.front() * 2 <= cur)
{
trash.push_back(node.front());
kmod[2 * node.front() % k]--;
node.pop_front();
}
ans[cur] = kmod[cur % k];
if (cur % k == 0)
ans[cur]++;
node.push_back(cur);
kmod[2 * cur % k]++;
for (const int &i : adj[cur])
dfs(i, cur);
while (!trash.empty() && trash.back() * 2 > fa)
{
node.push_front(trash.back());
kmod[trash.back() * 2 % k]++;
trash.pop_back();
}
kmod[2 * cur % k]--;
node.pop_back();
}
void solve()
{
cin >> s >> k;
n = s.length();
s = ' ' + s;
for (int i = 2, h = 0; i <= n; i++)
{
while (h && s[h + 1] != s[i])
h = nxt[h];
if (s[h + 1] == s[i])
h++;
nxt[i] = h;
adj[h].push_back(i);
}
adj[0].push_back(1);
dfs(0, -1);
int sum = 1;
for (int i = 1; i <= n; i++)
sum = (i64)sum * (ans[i] + 1) % 998244353;
for (int i = 0; i < n; i++)
adj[i].clear();
node.clear();
trash.clear();
fill(kmod, kmod + k, 0);
cout << sum << '\n';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 492ms
memory: 165776kb
input:
10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...
output:
811844748 106557744 583082277 750875845 539889742 198008691 286657978 344446711 612851418 36100066
result:
ok 10 lines