QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460732#4375. StringhowardleeWA 98ms21804kbC++171.7kb2024-07-02 04:40:512024-07-02 04:40:52

Judging History

你现在查看的是最新测评结果

  • [2024-07-02 04:40:52]
  • 评测
  • 测评结果:WA
  • 用时:98ms
  • 内存:21804kb
  • [2024-07-02 04:40:51]
  • 提交

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'