QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56585#4375. StringqinjianbinRE 0ms0kbC++1.4kb2022-10-20 12:04:132022-10-20 12:04:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-20 12:04:15]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-10-20 12:04:13]
  • 提交

answer

#include<iostream>
#include<cstring>
#define ll long long
using namespace std;

const int MAXN = 1e6 + 10;
const int MOD = 998244353;
char str[MAXN];
int z[MAXN], len;

void GetZ(char str[], int n, int z[]) {
    int l = 0, r = 0;
    z[0] = n;
    for (int i = 1; i < n; i++) {
        z[i] = i > r ? 0 : min(r - i + 1, z[i - l]);
        while (z[i] + i < n && str[z[i]] == str[i + z[i]]) z[i]++;
        if (i + z[i] - 1 > r) {
            l = i;
            r = i + z[i] - 1;
        }
    }
}
int T;
int k;
int a[MAXN];
int main() {
#ifdef TanJI
    freopen("D:\\Cpp\\1.in", "r", stdin);
    freopen("D:\\Cpp\\1.out", "w", stdout);
#endif
    scanf("%d", &T);
    while (T--) {
        scanf("%s", str);
        scanf("%d", &k);
        len = strlen(str);
        GetZ(str, len, z);
        for (int i = 0; i < len; i++) a[i] = 0;
        for (int i = 0; i < len; i++) {
            //z[i]是长度,z[i] - 1是下标,
            if (z[i] > i) {
                int l = (z[i] - i) / k - 1, r = -1;
                int offset = i + z[i] - 1 - ((z[i] - i) % k);
                a[offset - l * k]++;
                a[offset - r * k]--;
            }
        }
        for (int i = k; i < len; i++) {
            a[i] += a[i - k];
        }
        ll ans = 1;
        for (int i = 0; i < len; i++) 
            ans = ans * (a[i] + 1) % MOD;
        printf("%lld\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:


result: