QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#296187#7876. Cyclic Substringsucup-team870#WA 0ms11828kbC++141.3kb2024-01-02 13:33:242024-01-02 13:33:24

Judging History

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

  • [2024-01-02 13:33:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11828kb
  • [2024-01-02 13:33:24]
  • 提交

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