QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#597793 | #7876. Cyclic Substrings | lzx2017 | WA | 706ms | 718160kb | C++20 | 4.9kb | 2024-09-28 18:49:01 | 2024-09-28 18:49:02 |
Judging History
answer
#include<bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
using namespace std;
const int N=3e6+10;
const int mod=998244353;
int i,j,n,m,k,l,a[N*4],tree[N*2][11],root,num,r,d[N*4],wz,f[N*2][24],pos[N*4],g[N*2],qz[30],x,y;
long long ans;
string s;
inline void update(int x)
{
for(int i=1;i<=23;i++)
f[x][i]=f[f[x][i-1]][i-1];
}
inline int up(int x,int y)
{
for(int i=23;i>=0;i--) if(qz[i]<=y) x=f[x][i],y-=qz[i];
return x;
}
inline void dfs1(int x,int y,int dep,int hh)
{
for(int i=0;i<=10;i++)
if(tree[x][i])
{
if(x==0)
{
if(i==10) dfs1(tree[x][i],1,dep+1,i);
else dfs1(tree[x][i],0,dep+1,i);
}
else dfs1(tree[x][i],y,dep+1,i);
g[x]+=g[tree[x][i]];
}
if(x&&hh!=10)
{
if(y)
{
int gs=dep/2; gs*=2;
if(gs<=n)ans+=gs*g[x]%mod*g[x]%mod;
ans%=mod;
}
else
{
int gs=dep/2+(dep%2!=0); gs=gs*2-1;
if(gs<=n)ans+=gs*g[x]%mod*g[x]%mod;
ans%=mod;
}
}
}
int main()
{
// freopen("1.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>s;
a[0]=0;a[++a[0]]=10;
for(i=1;i<=n;i++)
{
a[++a[0]]=s[i-1]-'0';
a[++a[0]]=10;
}
for(i=1;i<=n;i++)
{
a[++a[0]]=s[i-1]-'0';
a[++a[0]]=10;
}
qz[0]=1;
for(i=1;i<=23;i++) qz[i]=qz[i-1]*2;
root=0;num=0;
for(i=1,l=1,r=0;i<=2*n;i++)
{
wz=root;
if(!tree[wz][a[i]]){
tree[wz][a[i]]=++num;
f[num][0]=wz;
update(num);
}
wz=tree[root][a[i]];
if(i>r)
{
k=1;
g[wz]++;
g[f[wz][0]]--;
}
else
{
if(d[l+r-i]<=r-i+1)
{
k=d[l+r-i];
x=pos[l+r-i];
g[x]++;
g[f[wz][0]]--;
wz=x;
}
else
{
k=r-i+1;
y=d[l+r-i]-(r-i+1);
x=pos[l+r-i];
x=up(x,y);
g[x]++;
g[f[wz][0]]--;
wz=x;
}
}
while(1<=i-k&&i+k<=4*n+2&&a[i-k]==a[i+k]){
if(!tree[wz][a[i+k]])
{
tree[wz][a[i+k]]=++num;
f[num][0]=wz;
update(num);
}
g[wz]--;
g[tree[wz][a[i+k]]]++;
wz=tree[wz][a[i+k]];
k++;
}
pos[i]=wz;
d[i]=k--;
if(i+k>r){
l=i-k;
r=i+k;
}
}
for(i=2*n+1,l=1,r=0;i<=4*n+1;i++)
{
wz=root;
if(!tree[wz][a[i]]){
tree[wz][a[i]]=++num;
f[num][0]=wz;
update(num);
}
wz=tree[root][a[i]];
if(i>r)
{
k=1;
g[wz]++;
g[f[wz][0]]--;
}
else
{
if(d[l+r-i]<=r-i+1)
{
k=d[l+r-i];
x=pos[l+r-i];
g[x]++;
g[f[wz][0]]--;
wz=x;
}
else
{
k=r-i+1;
y=d[l+r-i]-(r-i+1);
x=pos[l+r-i];
x=up(x,y);
g[x]++;
g[f[wz][0]]--;
wz=x;
}
}
while(1<=i-k&&i+k<=4*n+2&&a[i-k]==a[i+k]){
if(!tree[wz][a[i+k]])
{
tree[wz][a[i+k]]=++num;
f[num][0]=wz;
update(num);
}
g[wz]--;
g[tree[wz][a[i+k]]]++;
wz=tree[wz][a[i+k]];
k++;
}
pos[i]=wz;
d[i]=k--;
int len=0;
if(i-d[i]+1<=2*n) len=i-(2*n);
else len=d[i];
x=pos[i]; y=d[i]-len;
x=up(x,y);
g[x]--;
if(i+k>r){
l=i-k;
r=i+k;
}
}
dfs1(root,0,0,10);
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 13972kb
input:
5 01010
output:
39
result:
ok 1 number(s): "39"
Test #2:
score: 0
Accepted
time: 0ms
memory: 13968kb
input:
8 66776677
output:
192
result:
ok 1 number(s): "192"
Test #3:
score: 0
Accepted
time: 2ms
memory: 13780kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 13920kb
input:
2 22
output:
12
result:
ok 1 number(s): "12"
Test #5:
score: 0
Accepted
time: 0ms
memory: 13964kb
input:
2 21
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 2ms
memory: 13896kb
input:
3 233
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 0ms
memory: 13968kb
input:
3 666
output:
54
result:
ok 1 number(s): "54"
Test #8:
score: -100
Wrong Answer
time: 706ms
memory: 718160kb
input:
1000000 3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333...
output:
-326878921
result:
wrong answer 1st numbers differ - expected: '496166704', found: '-326878921'