QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638696#7876. Cyclic SubstringsWinding#WA 0ms3548kbC++232.0kb2024-10-13 16:38:402024-10-13 16:38:41

Judging History

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

  • [2024-10-13 16:38:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3548kb
  • [2024-10-13 16:38:40]
  • 提交

answer

//
// Created by wind on 24-10-13.
//

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 3e6 + 10, mod = 998244353;

struct pam{
    int sz, tot, last;
    int cnt[N], ch[N][26], len[N], fail[N];
    char s[N];

    int node(int l)
    {
        sz ++;
        memset(ch[sz], 0, sizeof (ch[sz]));
        len[sz] = 1;
        fail[sz] = cnt[sz] = 0;
        return sz;
    }

    void clear()
    {
        sz = -1;
        last = 0;
        s[tot = 0] = '$';
        node(0);
        node(-1);
        fail[0] = 1;
    }

    int getfail(int x)
    {
        while(s[tot - len[x] - 1] != s[tot])
            x = fail[x];
        return x;
    }

    void insert(char c) {
        s[++tot] = c;
        int now = getfail(last);
        if (!ch[now][c - 'a']) {
            int x = node(len[now] + 2);
            fail[x] = ch[getfail(fail[now])][c - 'a'];
            ch[now][c - 'a'] = x;
        }
        last = ch[now][c - 'a'];
        cnt[last]++;
    }
    int work(int op)
    {
        int ans = 0;
        for(int i = sz; i >= 0; i --)
        {
            cnt[fail[i]] += cnt[i];
        }
        for(int i = 1; i <= sz; i ++)
        {
            if(op == 2 && len[i] >= tot) continue;
            ans += 1ll * cnt[i] * cnt[i] % mod * len[i] % mod;
            ans %= mod;
        }
        return ans;
    }
};

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t = s + s;
    exit(0);
    pam p1, p2;
    p1.clear(), p2.clear();
    for(int i = 0; i < s.size(); i ++)
        p1.insert(s[i]);
    for(int i = 0; i < t.size(); i ++)
        p2.insert(t[i]);
    int ans = p2.work(2) - p1.work(1);
    ans = (ans % mod + mod) % mod;
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

/*
5
01010
 */

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3548kb

input:

5
01010

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements