QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#724733 | #4375. String | XfJbUhpyzgaW# | WA | 124ms | 8492kb | C++14 | 986b | 2024-11-08 14:48:55 | 2024-11-08 14:48:56 |
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;
}
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();
}
详细
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'