QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#271346#7876. Cyclic Substringsucup-team1209#AC ✓782ms823860kbC++201.9kb2023-12-02 10:48:172023-12-02 10:48:17

Judging History

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

  • [2023-12-02 10:48:17]
  • 评测
  • 测评结果:AC
  • 用时:782ms
  • 内存:823860kb
  • [2023-12-02 10:48:17]
  • 提交

answer

#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int mod = 998244353; 
cs int N = 6e6 + 5; 

int n;
string S;
namespace pam {
    int ch[N][10], len[N], lk[N], rp, las, nd; 
    int sz[N], ans; 
    int sz0[N]; 
    void init() {
        rp = 0;
        las = nd = 1; 
        len[1] = -1;
        lk[0] = 1; 
    }
    int jmp(int x) {
        while(S[rp - len[x] - 1] != S[rp]) x = lk[x]; return x;
    }
    void ins(int c) {
        ++ rp; 
        int p = jmp(las);
        if(!ch[p][c]) {
            int x = ++ nd; 
            len[x] = len[p] + 2;
            lk[x] = ch[jmp(lk[p])][c];
            ch[p][c] = x; 
        }
        las = ch[p][c];
        if(rp <= n) ++ sz0[las];
        ++ sz[las];
    }
    vector <int> e[N];
    void dfs0(int u) {
        for(int v : e[u]) 
            dfs0(v), sz0[u] += sz0[v];
    }
    void dfs(int u) {
        for(int v : e[u]) 
            dfs(v), sz[u] += sz[v]; 
        if(len[u] > 0 && len[u] <= n) {
            int s = sz[u] - sz0[u];
            ans = (ans + 1ll * s * s % mod * len[u] % mod) % mod; 
        }
    }
    void work0() {
        for(int i = 0; i <= nd; i++) 
            if(i != 1) e[lk[i]].pb(i);
        dfs0(1);
        for(int i = 0; i <= nd; i++) e[i].clear();
    }
    int work() {
        ans = 0; 
        for(int i = 0; i <= nd; i++) 
            if(i != 1) e[lk[i]].pb(i);
        dfs(1);
        for(int i = 0; i <= nd; i++) e[i].clear();
        return ans; 
    }
}

int main() {
    #ifdef zqj
    freopen("1.in","r",stdin);
    #endif
    ios :: sync_with_stdio(0), cin.tie(0);
    cin >> n >> S; 
    S = '#' + S + S; 
    pam :: init();
    for(int i = 1; i <= n + n; i++) {
        pam :: ins(S[i] - '0'); 
        if(i == n) {
            pam :: work0();
        }
    }
    cout << pam :: work()<< '\n';
    return 0; 
}

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

詳細信息

Test #1:

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

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

score: 0
Accepted
time: 18ms
memory: 151408kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 24ms
memory: 151124kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 29ms
memory: 152140kb

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 103ms
memory: 373208kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 340ms
memory: 823860kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: 0
Accepted
time: 181ms
memory: 360064kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

224009870

result:

ok 1 number(s): "224009870"

Test #11:

score: 0
Accepted
time: 411ms
memory: 738244kb

input:

3000000
8989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989898989...

output:

51985943

result:

ok 1 number(s): "51985943"

Test #12:

score: 0
Accepted
time: 432ms
memory: 710484kb

input:

3000000
1911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911911...

output:

355676465

result:

ok 1 number(s): "355676465"

Test #13:

score: 0
Accepted
time: 268ms
memory: 556864kb

input:

3000000
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777...

output:

788510374

result:

ok 1 number(s): "788510374"

Test #14:

score: 0
Accepted
time: 256ms
memory: 543148kb

input:

3000000
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555...

output:

691884476

result:

ok 1 number(s): "691884476"

Test #15:

score: 0
Accepted
time: 782ms
memory: 372492kb

input:

3000000
0990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990990909909909099090990990909909909099090990990909909099099090990990909909099099090990990909909099099090990909909909099099090990909909909099090990...

output:

701050848

result:

ok 1 number(s): "701050848"

Test #16:

score: 0
Accepted
time: 233ms
memory: 222652kb

input:

3000000
2772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772772727727727277272772772727727727277272772772727727277277272772772727727277277272772772727727277277272772727727727277277272772727727727277272772...

output:

486861605

result:

ok 1 number(s): "486861605"

Test #17:

score: 0
Accepted
time: 698ms
memory: 495344kb

input:

3000000
4554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554554545545545455454554554545545545455454554554545545455455454554554545545455455454554554545545455455454554545545545455455454554545545545455454554...

output:

450625621

result:

ok 1 number(s): "450625621"

Test #18:

score: 0
Accepted
time: 713ms
memory: 485208kb

input:

3000000
1181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181811811818118181181181811818118118181181181811818118118181181181811818118118181181811811818118118181181811811818118181181181811811818118181181181...

output:

649551870

result:

ok 1 number(s): "649551870"

Extra Test:

score: 0
Extra Test Passed