QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724733#4375. StringXfJbUhpyzgaW#WA 124ms8492kbC++14986b2024-11-08 14:48:552024-11-08 14:48:56

Judging History

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

  • [2024-11-08 14:48:56]
  • 评测
  • 测评结果:WA
  • 用时:124ms
  • 内存:8492kb
  • [2024-11-08 14:48:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1000100, M = 998244353;
char s[N];
int n, k, nxt[N];

int exgcd(int a, int b, int &x, int &y) {
    if (!b) { x = 1, y = 0; return a; }
    int g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

void solve() {
    cin >> s + 1 >> k;
    n = strlen(s + 1);
    nxt[0] = -1;

    long long ans = 1;
    for (int i = 1; i <= n; i++) {
        int p = nxt[i - 1];
        while (~p && s[p + 1] != s[i]) p = nxt[p];
        nxt[i] = p + 1;

        int t = 2 * (i - nxt[i]), x, y;
        int g = exgcd(t, k, x, y);
        if (i % g != 0) continue;
        x = 1ll * x * (i / g) % k;
        y = 1ll * y * (i / g) % t;

        auto q = 1ll * k / g * t;

        int num = (i - x + q - 1) / q;
        ans = ans * (1 + num) % M;
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(0)->sync_with_stdio(0), cout.tie(0);
    int T;
    for (cin >> T; T; T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 124ms
memory: 8492kb

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:

442569784
990555934
174987859
408908058
539889742
51722821
886365260
571739460
291475600
48767177

result:

wrong answer 1st lines differ - expected: '811844748', found: '442569784'