QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645413#7876. Cyclic Substringsblack_king1WA 108ms343484kbC++172.4kb2024-10-16 18:15:112024-10-16 18:15:15

Judging History

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

  • [2024-10-16 18:15:15]
  • 评测
  • 测评结果:WA
  • 用时:108ms
  • 内存:343484kb
  • [2024-10-16 18:15:11]
  • 提交

answer

// Created by calabash_boy on 18-6-4.
// BZOJ 3676
// calc max(len(t)*cnt(t)) t为s回文子串,cnt(t)=t出现次数
#include<bits/stdc++.h>
using namespace std;
const int maxn = 6e6+100;
const int mod = 998244353;

struct Palindromic_AutoMaton{
    //basic
    int s[maxn],now;
    int nxt[maxn][10],fail[maxn],l[maxn],last,tot;
    // extension
    int num[maxn];/*节点代表的所有回文串出现次数*/
    bool two,flag[maxn];
    void clear(){
        //1节点:奇数长度root 0节点:偶数长度root
        s[0]=l[1]=-1;
        two=false;
        fail[0] = tot = now =1;
        last = l[0]=0;
        memset(nxt[0],0,sizeof nxt[0]);
        memset(nxt[1],0,sizeof nxt[1]);
        memset(flag,0,sizeof(flag));
    }
    Palindromic_AutoMaton(){clear();}
    int newnode(int ll){
        tot++;
        memset(nxt[tot],0,sizeof nxt[tot]);
        fail[tot]=num[tot]=0;
        flag[tot]=two;
        l[tot]=ll;
        return tot;
    }
    int get_fail(int x){
        while (s[now-l[x]-2]!=s[now-1])x = fail[x];
        return x;
    }
    void add(int ch){
        s[now++] = ch;
        int cur = get_fail(last);
        if(!nxt[cur][ch]){
            int tt = newnode(l[cur]+2);
            fail[tt] = nxt[get_fail(fail[cur])][ch];
            nxt[cur][ch] = tt;
        }
        last = nxt[cur][ch];
        if(flag[last]){
            num[last]++;
        }
    }
    void build(){
        //fail[i]<i,拓扑更新可以单调扫描。
        for (int i=tot;i>=2;i--){
            num[fail[i]]+=num[i];
        }
        num[0]=num[1]=0;
    }
    void init(char* ss){
        while (*ss){
            add(*ss-'0');ss++;
        }
    }
    void init(string str){
        for (int i=0;i<str.size();i++){
            add(str[i]-'0');
        }
    }
    long long query(string s);
}pam;
string s;
long long Palindromic_AutoMaton::query(string s){
    long long ret =0;
    for (int i=2;i<=tot;i++){
        if(l[i]<=s.size()){
            long long temp=1ll*num[i]*num[i]%mod;
            temp=1ll*temp*l[i]%mod;
            ret+=temp;
            ret%=mod;  
            //cout<<ret<<endl;
        }
    }
    return ret;
}

int main(){
    int n;scanf("%d",&n);
    cin>>s;
    pam.init(s);
    //cout<<s<<endl;
    pam.two=true;
    pam.init(s);
    pam.build();
    printf("%lld\n",pam.query(s));
    return 0;
}

详细

Test #1:

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

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 4ms
memory: 18088kb

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

score: 0
Accepted
time: 2ms
memory: 18224kb

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 47ms
memory: 134464kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 108ms
memory: 343484kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: -100
Wrong Answer
time: 100ms
memory: 183264kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

489110450

result:

wrong answer 1st numbers differ - expected: '224009870', found: '489110450'