QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#592860 | #7876. Cyclic Substrings | JZYZ# | WA | 31ms | 114720kb | C++14 | 857b | 2024-09-27 09:05:05 | 2024-09-27 09:05:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1.2e7+7;
int Next[N],len[N];
int tr[N][10],occ[N];
int n,m;
int pos[N];
int tot=1;
char s[N];
int getNext(int x,int i)
{
while(i-len[x]-1<0||s[i-len[x]-1]!=s[i]) x=Next[x];
return x;
}
int cur=0;
const int mod = 998244353;
int main()
{
cin>>n;
scanf("%s",s+1);
for(int i=1;i<=n;i++)s[i+n]=s[i];
reverse(s+1,s+2*n+1);
Next[0]=1;len[1]=-1;
int last=0;
for(int i=1;i<=2*n;i++)
{
int c=s[i]-'0';
int p=getNext(cur,i);
if(!tr[p][c])
{
int q=++tot;
Next[q]=tr[getNext(Next[p],i)][c];
tr[p][c]=q;
len[q]=len[p]+2;
}
cur=tr[p][c];
if(i>n)occ[cur]++;
}
int ans=0;
for(int i=tot;i>=2;i--)
{
occ[Next[i]]+=occ[i];
if(len[i]<=n)ans+=1ll*occ[i]*occ[i]%mod*len[i]%mod;
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9700kb
input:
5 01010
output:
39
result:
ok 1 number(s): "39"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9912kb
input:
8 66776677
output:
192
result:
ok 1 number(s): "192"
Test #3:
score: 0
Accepted
time: 1ms
memory: 9696kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 9700kb
input:
2 22
output:
12
result:
ok 1 number(s): "12"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9864kb
input:
2 21
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 9948kb
input:
3 233
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 0ms
memory: 9736kb
input:
3 666
output:
54
result:
ok 1 number(s): "54"
Test #8:
score: -100
Wrong Answer
time: 31ms
memory: 114720kb
input:
1000000 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
output:
-770013105
result:
wrong answer 1st numbers differ - expected: '496166704', found: '-770013105'