QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#667643#7876. Cyclic Substrings111111qqqqqqWA 88ms337048kbC++231.4kb2024-10-23 01:21:522024-10-23 01:21:56

Judging History

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

  • [2024-10-23 01:21:56]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:337048kb
  • [2024-10-23 01:21:52]
  • 提交

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>=2;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;
}

详细

Test #1:

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

input:

5
01010

output:

39

result:

ok 1 number(s): "39"

Test #2:

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

input:

8
66776677

output:

192

result:

ok 1 number(s): "192"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

2
22

output:

12

result:

ok 1 number(s): "12"

Test #5:

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

input:

2
21

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

3
233

output:

10

result:

ok 1 number(s): "10"

Test #7:

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

input:

3
666

output:

54

result:

ok 1 number(s): "54"

Test #8:

score: 0
Accepted
time: 27ms
memory: 121016kb

input:

1000000
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...

output:

496166704

result:

ok 1 number(s): "496166704"

Test #9:

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

input:

3000000
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

output:

890701718

result:

ok 1 number(s): "890701718"

Test #10:

score: -100
Wrong Answer
time: 75ms
memory: 154260kb

input:

3000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

960401003

result:

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