QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#528094#7876. Cyclic SubstringslongyinAC ✓144ms359392kbC++201.8kb2024-08-23 08:16:542024-08-23 08:16:55

Judging History

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

  • [2024-08-23 08:16:55]
  • 评测
  • 测评结果:AC
  • 用时:144ms
  • 内存:359392kb
  • [2024-08-23 08:16:54]
  • 提交

answer

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

using ll = long long;
const int MOD = 998244353;
const int N = 3e6 + 5;

string s;

struct PAM {
    int s[N * 2];
    int n, tot, last;
    struct Palindromic_Tree {
        int next[10];
        int len;
        int cnt; 
        int size;
        int fail;   // [最长回文后缀] 在回文树上对应的节点
    } tr[N * 4];

    PAM() {
        s[0] = 10;
        tr[0].fail = 1;
        tr[1].len = -1;
        tot = 1;
    }

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

    void insert(int x, bool flag) {
        s[++n] = x;
        int p = getfail(last);
        while (!tr[p].next[x]) {
            int cur = ++tot;
            tr[cur].len = tr[p].len + 2;
            tr[cur].fail = tr[getfail(tr[p].fail)].next[x];
            tr[cur].size = tr[tr[cur].fail].size + 1;
            tr[p].next[x] = cur;
        }
        last = tr[p].next[x];
        if (flag)
            tr[last].cnt++; 
    }

    void count() {
        for (int i = tot; i >= 2; i--) {
            tr[tr[i].fail].cnt = (1ll * tr[tr[i].fail].cnt + tr[i].cnt) % MOD;
        }
    }

    int getUniqueCount() {
        return tot - 1;
    }

    int cal(int n, string& t) {
        for (int i = 0; i < 2 * n; i++) {
            insert(t[i % n] - '0', i >= n);
        }

        count();
        
        int ans = 0;
        for (int i = 2; i <= tot; i++) {
            if (tr[i].len <= n)
                ans = (ans + 1ll * tr[i].len * tr[i].cnt % MOD * tr[i].cnt % MOD) % MOD;
        }
        return ans;
    }
} pam;

signed main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n;
    cin >> n;
    cin >> s;
    cout << pam.cal(n, s) << endl;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5660kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5660kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5660kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5688kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 0ms
memory: 5664kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 1ms
memory: 5684kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 46ms
memory: 126556kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 143ms
memory: 359124kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 113ms
memory: 179416kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 115ms
memory: 359360kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 129ms
memory: 359392kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 122ms
memory: 317592kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 144ms
memory: 330644kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 86ms
memory: 194864kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 42ms
memory: 79120kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 119ms
memory: 306912kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 99ms
memory: 301276kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed