QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#724778 | #4375. String | XfJbUhpyzgaW# | WA | 169ms | 8584kb | C++14 | 1.1kb | 2024-11-08 15:01:38 | 2024-11-08 15:01:38 |
Judging History
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;
}
int foo(int t, int k, int v) { // tx + ky = v, x,y >= 0
if (v < 0) return 0;
int x, y;
int g = exgcd(t, k, x, y);
if (v % g != 0) return 0;
t /= g, k /= g, v /= g;
x = 1ll * x * v % k;
if (x < 0) x += k;
assert(1ll * t * x % k == v % k);
long long a = v - 1ll * x * t, b = 1ll * k * t;
return a / b + 1;
}
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;
ans = ans * (1 + foo(2 * (i - nxt[i]), k, i - k)) % M;
}
cout << ans << "\n";
}
int main() {
cin.tie(0)->sync_with_stdio(0), cout.tie(0);
int T;
for (cin >> T; T; T--) solve();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 169ms
memory: 8584kb
input:
10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...
output:
811844748 106557744 583082277 163420225 539889742 396017382 286657978 519925611 612851418 627831036
result:
wrong answer 4th lines differ - expected: '750875845', found: '163420225'