QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#103451 | #4375. String | zbceyond | TL | 0ms | 0kb | C++20 | 1.3kb | 2023-05-05 21:49:13 | 2023-05-05 21:49:16 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;i++)
using namespace std;
const int N = 1e6+10;
const int mod = 998244353;
int qmi(int a,int b) {
int res = 1;
for (; b; b >>= 1, a = a * a % mod) {
if (b & 1)res = res * a % mod;
}
return res;
}
vector<int>e[N];
int k,nxt[N],cnt[N],ans,f[N];
void dfs(int u) {
int x = cnt[u % k] + 1;
if (u % k == 0 and u != 0)x++;
f[u]=x;
//ans = ans * x % mod;
if(u!=0)cnt[u * 2 % k]++;
for (auto &v: e[u]) {
dfs(v);
}
if(u!=0)cnt[u * 2 % k]--;
}
void solve(int tc) {
string s;
cin >> s >> k;
s = " " + s;
int n = s.size();
for (int i = 0; i < n; i++)e[i].clear();
e[0].push_back(1);
for (int i = 2, j = 0; i < n; i++) {
while (j and s[j + 1] != s[i])j = nxt[j];
while (2*j >= i)j = nxt[j];
if (s[j + 1] == s[i]) {
j++;
if (2*j>=i)j = nxt[j];
}
nxt[i] = j;
//cout << i << " " << j << "\n";
e[j].push_back(i);
}
dfs(0);
ans = 1;
for (int i = 1; i < n; i++)ans = (long long)ans * f[i] % mod;
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc = 1;
cin >> tc;
for (int i = 1; i <= tc; i++) {
solve(i);
}
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...