QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296187 | #7876. Cyclic Substrings | ucup-team870# | WA | 0ms | 11828kb | C++14 | 1.3kb | 2024-01-02 13:33:24 | 2024-01-02 13:33:24 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N = 6000010, mod = 998244353;
int lst, fail[N], ch[N][10], l[N], tot, pos[N], sum[N];
char s[6000010];
int Insert(int x, int c, int tag) {
int p = lst;
while (s[x - l[p] - 1] ^ c) p = fail[p];
if (!ch[p][c]) {
int now = ++tot, q = fail[p];
l[now] = l[p] + 2;
while (s[x - l[q] - 1] ^ c) q = fail[q];
fail[now] = ch[q][c];
ch[p][c] = now;
}
sum[ch[p][c]]+= tag;
return lst = ch[p][c];
}
int main() {
int n; scanf("%d", &n);
scanf("%s", s+1);
rep (i, 1, n) s[i] -= '0';
rep (i, 1, n) s[i+n] = s[i];
s[0] = -1, tot = 1, l[1] = -1, fail[0] = 1;
// cout << s+1;
rep (i, 1, n*2) {
pos[i] = Insert(i, s[i], i > n);
// cout <<"$$$\n";
}cout <<"#";
per (i, tot, 0) {
sum[fail[i]] += sum[i];
}
ll ans = 0;
rep (i, 0, tot) {
if (l[i] > 0 && l[i] <= n) {
ans = (ans + 1ll * sum[i] * sum[i] % mod * l[i]) % mod;
}
}
cout << ans;
return 0;
}
/*
5
01010
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11828kb
input:
5 01010
output:
#39
result:
wrong output format Expected integer, but "#39" found