QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771898#7876. Cyclic SubstringsfosovAC ✓168ms720056kbC++142.2kb2024-11-22 16:13:362024-11-22 16:13:37

Judging History

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

  • [2024-11-22 16:13:37]
  • 评测
  • 测评结果:AC
  • 用时:168ms
  • 内存:720056kb
  • [2024-11-22 16:13:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define lll __int128
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define fi first
#define se second
#define all(a) a.begin(), a.end()

#define N 200010

struct mint {
    static const int MOD = 998244353;
    ll v;
    mint() {};
    mint(ll v): v(v%MOD) {};

    mint operator+(mint x) {
        return v + x.v;
    }
    mint operator*(mint x) {
        return v * x.v;
    }
};

namespace PAM {
    static const int P = 6000010;
    int z, sz, last;
    int ch[P][26], len[P], fail[P];
    mint cnt[P];
    char s[P];

    int add_node(int l) {
        int cu = z ++;
        len[cu] = l;
        return cu;
    }

    int next(int x) {
        return s[sz-len[x]-1] == s[sz] ? x : next(fail[x]);
    }

    void init() {
        z = sz = 0;
        s[sz] = '$';
        memset(ch, 0, sizeof(ch));
        memset(len, 0, sizeof(len));
        memset(fail, 0, sizeof(fail));
        memset(cnt, 0, sizeof(cnt));
        last = add_node(0);
        fail[last] = add_node(-1);
    }

    void insert(char c, int flag) {
        s[++ sz] = c;
        int cur = next(last);
        if (!ch[cur][c-'0']) {
            int cu = add_node(len[cur] + 2);
            fail[cu] = ch[next(fail[cur])][c-'0'];
            ch[cur][c-'0'] = cu;
        }
        last = ch[cur][c-'0'];
        cnt[last] = cnt[last] + flag;
    }

    mint count(int n) {
        mint res = 0;
        for (int i = z-1; i >= 0; -- i) cnt[fail[i]] = cnt[fail[i]] + cnt[i];
        for (int i = 0; i < z; ++ i) {
            if (len[i] > 0 && len[i] <= n) {
                res = res + cnt[i] * cnt[i] * len[i];
            }
        }
        return res;
    }
};

int main() {
#ifdef TEST
    freopen("zz.in", "r+", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n; cin >> n;
    string s; cin >> s;
    s += s;
    PAM::init();
    for (int i = 0; i < s.length(); ++ i) {
        PAM::insert(s[i], i >= n);
    }
    cout << PAM::count(n).v << '\n';

} 

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

score: 0
Accepted
time: 35ms
memory: 706748kb

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 35ms
memory: 706672kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 39ms
memory: 706672kb

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 63ms
memory: 710300kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 168ms
memory: 718900kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 131ms
memory: 720056kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 128ms
memory: 719548kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

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

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 163ms
memory: 718748kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 152ms
memory: 718160kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

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

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 112ms
memory: 718316kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 149ms
memory: 719276kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

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

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed