QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#273561#7876. Cyclic Substringsucup-team296#AC ✓187ms413164kbC++142.7kb2023-12-03 01:24:292023-12-03 01:24:29

Judging History

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

  • [2023-12-03 01:24:29]
  • 评测
  • 测评结果:AC
  • 用时:187ms
  • 内存:413164kb
  • [2023-12-03 01:24:29]
  • 提交

answer

#include <bits/stdc++.h>

#define long long long int
#define DEBUG
using namespace std;

// @author: pashka

long mod = 998244353;

const int maxn = 6000010;
const int sigma = 10;
int n = 0;
char s[maxn];
long nm1[maxn];
long nm2[maxn];

struct palindrome_tree {
    struct state {
        int len, link;
        int to[sigma];
        long num;

        state() : len(-1), link(-1) {}
    } st[maxn];

    int last, sz;

    palindrome_tree() : last(1), sz(2) { st[1].len = st[1].link = 0; }

    int add_letter() {
        char c = s[n - 1];
        int p = last;
        while (p != -1 && c != s[n - st[p].len - 2]) p = st[p].link;
//        if (st[p].len == 5) {
//            cout << "!!!\n";
//        }
        if (p == -1) {
            last = 1;
            st[last].num++;
//            cout << (int)c << " " << last << " " << st[last].len << "\n";
            return 0;
        }
        int ret = 0;
        if (!st[p].to[c]) {
            ret = 1;
            int q = last = sz++;
            st[p].to[c] = q;
            st[q].len = st[p].len + 2;
            do
                p = st[p].link;
            while (p != -1 && c != s[n - st[p].len - 2]);
            if (p == -1)
                st[q].link = 1;
            else
                st[q].link = st[p].to[c];
        } else
            last = st[p].to[c];
        st[last].num++;
//        cout << (int)c << " " << last << " " << st[last].len << "\n";
        return ret;
    }
};

palindrome_tree me;

int main() {
    ios::sync_with_stdio(false);
    int nn;
    cin >> nn;
    string ss;
    cin >> ss;
    ios::sync_with_stdio(0);
    s[n++] = '#';
    {
        int i = 0;
        while ((s[n++] = ss[i++]) != 0) {
            s[n - 1] -= '0';
            me.add_letter();
        }
    }
    n--;
    for (int i = me.sz - 1; i > 0; i--) {
        nm1[i] += me.st[i].num;
        nm1[me.st[i].link] += nm1[i];
    }
    {
        int i = 0;
        while ((s[n++] = ss[i++]) != 0) {
            s[n - 1] -= '0';
            me.add_letter();
        }
    }
    for (int i = me.sz - 1; i > 0; i--) {
        nm2[i] += me.st[i].num;
        nm2[me.st[i].link] += nm2[i];
    }

    long res = 0;
    for (int i = 0; i < me.sz; i++) {
        if (me.st[i].len > nn) continue;
        if (me.st[i].len <= 0) continue;
        long num = nm2[i] - nm1[i];
//        cout << me.st[i].len << " " << nm1[i] << " " << nm2[i] << "\n";
        long r = num;
        r %= mod;
        r *= r;
        r %= mod;
        r *= me.st[i].len;
        r %= mod;
//        cout << r << "\n";
        res += r;
        res %= mod;
    }
    cout << res << "\n";
    return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 24ms
memory: 333984kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 28ms
memory: 334776kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 16ms
memory: 333712kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 15ms
memory: 333944kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 12ms
memory: 334248kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 20ms
memory: 334964kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 19ms
memory: 335540kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 67ms
memory: 360672kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 147ms
memory: 412508kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 157ms
memory: 381516kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

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

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 160ms
memory: 412224kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 187ms
memory: 403288kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 165ms
memory: 406664kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 120ms
memory: 388912kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 72ms
memory: 357692kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 160ms
memory: 399668kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 159ms
memory: 396204kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed