QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#271352#7876. Cyclic Substringsucup-team045#AC ✓227ms329196kbC++202.1kb2023-12-02 10:54:312023-12-02 10:54:32

Judging History

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

  • [2023-12-02 10:54:32]
  • 评测
  • 测评结果:AC
  • 用时:227ms
  • 内存:329196kb
  • [2023-12-02 10:54:31]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
const int maxn = 6e6 + 5;
struct Node{
    int fa, len, cnt;
    int ch[10];
}node[maxn];
char s[maxn];
int bk[maxn];
int tot = 1;

int get_fail(int x, int i){
    while(s[i - node[x].len - 1] != s[i]) x = node[x].fa;
    return x;
}

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) 
        cin >> s[i], s[i + n] = s[i];
    node[0].fa = 1, node[1].len = -1;
    int last = 0;
    for(int i = 1; i <= n; i++){
        int c = s[i] - '0';
        int pos = get_fail(last, i);
        if (!node[pos].ch[c]){
            node[++tot].fa = node[get_fail(node[pos].fa, i)].ch[c];
            node[pos].ch[c] = tot;
            node[tot].len = node[pos].len + 2;
        }
        last = node[pos].ch[c];
        node[last].cnt++;
    }
    for(int i = tot; i; i--){
        node[node[i].fa].cnt += node[i].cnt;
    }
    for(int i = 0; i <= tot; i++){
        bk[i] = node[i].cnt;
        node[i].cnt = node[i].fa = node[i].len = 0;
        memset(node[i].ch, 0, sizeof node[i].ch);
    }
    node[0].fa = 1, node[1].len = -1;
    last = 0; tot = 1;
    for(int i = 1; i <= 2 * n; i++){
        int c = s[i] - '0';
        int pos = get_fail(last, i);
        if (!node[pos].ch[c]){
            node[++tot].fa = node[get_fail(node[pos].fa, i)].ch[c];
            node[pos].ch[c] = tot;
            node[tot].len = node[pos].len + 2;
        }
        last = node[pos].ch[c];
        node[last].cnt++;
    }
    for(int i = tot; i; i--){
        node[node[i].fa].cnt += node[i].cnt;
    }
    const int mod = 998244353;
    LL ans = 0;
    for(int i = 1; i <= tot; i++){
        if (node[i].len <= n){
            int cnt = node[i].cnt - bk[i];
            ans += 1LL * node[i].len * cnt % mod * cnt % mod;
            ans %= mod;
        }
    }
    cout << ans << '\n';

}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7632kb

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 60ms
memory: 113960kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 172ms
memory: 327144kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 196ms
memory: 159360kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 180ms
memory: 327124kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 175ms
memory: 329196kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 219ms
memory: 287548kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 227ms
memory: 298988kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 172ms
memory: 178704kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

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

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 179ms
memory: 276112kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 161ms
memory: 269324kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed