QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#668189#7876. Cyclic Substrings111111qqqqqqWA 92ms337124kbC++231.4kb2024-10-23 12:19:282024-10-23 12:19:32

Judging History

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

  • [2024-10-23 12:19:32]
  • 评测
  • 测评结果:WA
  • 用时:92ms
  • 内存:337124kb
  • [2024-10-23 12:19:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define modd(a,b) a=a%b
#define pb push_back
#define db double
#define lowbit(x) x&(-x)
#define cerr(x) cout<<#x<<"="<<x<<endl
const ll mod=998244353;
ll ksm(ll a,ll b) {ll ans=1,bs=a;while(b) {if(b&1) ans=ans*bs%mod;bs=bs*bs%mod;b>>=1;}return ans;}
#define fi first
#define se second
#define N 3000010<<1
int n;
string s;
int t[N][10];
ll ans=0;
int cur=0,pos=0,tot=1;
int fail[N],len[N];
ll num[N];
int getfail(int x,int i) {
    while(i-1-len[x]<0 || s[i]!=s[i-1-len[x]]) x=fail[x];
    return x;
}
void solve() {
    cin>>n>>s;
    s=s+s;
    fail[0]=1,len[1]=-1;
    for(int i=0;i<2*n;i++) {
        pos=getfail(cur,i);
        if(!t[pos][s[i]-'0']) {
            fail[++tot]=t[getfail(fail[pos],i)][s[i]-'0'];
            len[tot]=len[pos]+2;
            t[pos][s[i]-'0']=tot;
        }
        cur=t[pos][s[i]-'0'];
        if(i>=n) {
            num[tot]++;
        }
    }
    for(int i=tot;i>=1;i--) {
        int v=fail[i];
        num[v]+=num[i];
        // num[v]%=mod;
    }
    for(int i=2;i<=tot;i++) if(len[i]<=n) ans+=num[i]*num[i]%mod*len[i]%mod,ans%=mod;
    cout<<ans<<endl;
}
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // int T;
    // cin>>T;
    // while(T--) 
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 31ms
memory: 117588kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

score: 0
Accepted
time: 92ms
memory: 337124kb

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: -100
Wrong Answer
time: 68ms
memory: 154536kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

960401003

result:

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