QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#460732 | #4375. String | howardlee | WA | 98ms | 21804kb | C++17 | 1.7kb | 2024-07-02 04:40:51 | 2024-07-02 04:40:52 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define fastio ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int mod = 998244353;
// 一個字串的後綴可以和字串本身匹配到多長從第i項開始一路到n-1
inline vector<int> z_function(string s)
{
int n = s.size();
vector<int> z(n, 0);
for(int i = 1, l = 0, r = 0; i < n; i++) {
if(i <= r && z[i - l] < r - i + 1) {
z[i] = z[i - l];
}
else {
z[i] = max(0, r - i + 1);
while(i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;
}
if(i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
z[0] = n;
return z;
}
void solve()
{
// cin >> n;
string s;
cin >> s;
int n = s.size();
int k;
cin >> k;
vector<int> z = z_function(s);
vector<int> cnt(n, 0);
vector<int> v(n + 1, 0);
for(int i = 0; i < n; i++) {
if(z[i] - i < 0) continue;
int lens = z[i] - i; // len of choose substring
int step_to_next = lens / k;
int start = i * 2 + k - 1;
int stop = start + step_to_next * k;
if(start < n) v[start]++;
if(stop < n) v[stop]--;
}
vector<int> ans(n, 0);
for(int i = 0; i < k; i++) {
int now = 0;
for(int j = i; j < n; j += k) {
now += v[j];
ans[j] = now;
}
}
int final_ans = 1;
for(int i = 0; i < n; i++) {
final_ans = (final_ans * (ans[i] + 1)) % mod;
}
cout << final_ans << '\n';
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 98ms
memory: 21804kb
input:
10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...
output:
-140886226 888143888 -104385330 0 0 0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '811844748', found: '-140886226'