QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646975#7876. Cyclic SubstringsSGColinAC ✓131ms337136kbC++171.9kb2024-10-17 10:41:432024-10-17 10:41:49

Judging History

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

  • [2024-10-17 10:41:49]
  • 评测
  • 测评结果:AC
  • 用时:131ms
  • 内存:337136kb
  • [2024-10-17 10:41:43]
  • 提交

answer

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

#define eb emplace_back
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

const int A = 10;
const int N = 6000007;

const int mod = 998244353;

int n, ans = 0;

struct Palindromic_AutoMaton {
    vector<int> str;
    int nxt[N][A], fail[N], len[N];   
    int num[N], last, tot;
    void clear() {
        len[1] = -1; fail[1] = 0;
        len[0] = 0; fail[0] = 1;
        str.clear(); str.eb(-1);
        last = 0; tot = 1;
        memset(nxt[0], 0, sizeof(nxt[0]));
        memset(nxt[1], 0, sizeof(nxt[1]));
    }
    Palindromic_AutoMaton(){clear();}
    int newnode(int _len) {
        len[++tot] = _len;
        fail[tot] = num[tot] = 0; 
        memset(nxt[tot], 0, sizeof(nxt[tot]));
        return tot;
    }
    int get_fail(int u) {
        int strlen = str.size() - 1;
        while (str[strlen - len[u] - 1] != str[strlen]) u = fail[u];
        return u;
    }
    void append(int ch, int w) {
        str.emplace_back(ch);
        int fat = get_fail(last);
        if (!nxt[fat][ch]) {
            int cur = newnode(len[fat] + 2);
            fail[cur] = nxt[get_fail(fail[fat])][ch];
            nxt[fat][ch] = cur; 
        }
        last = nxt[fat][ch];
        num[last] += w;
    }
    void append(string &s, int w) {
        for (auto &ch : s) append(ch - '0', w);
    }
    void get_num() {
        per(u, tot, 2) num[fail[u]] += num[u];
        num[0] = num[1] = 0;
    }
    void calc() {
        rep(u, 2, tot) if (len[u] <= n) {
            int w = 1ll * num[u] * num[u] % mod * len[u] % mod;
            ans = (ans + w) % mod;
        }
    }
} pam;

int main() {
    cin.tie(0);
    ios::sync_with_stdio();
    cin >> n;
    string s; cin >> s;
    pam.append(s, 0);
    pam.append(s, 1);
    pam.get_num();
    pam.calc();
    cout << ans;
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9684kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 37ms
memory: 123328kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 102ms
memory: 336240kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

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

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 96ms
memory: 337136kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 96ms
memory: 336388kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

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

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 117ms
memory: 313584kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 94ms
memory: 202740kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 76ms
memory: 90784kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 88ms
memory: 296076kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 101ms
memory: 285948kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed