QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408148 | #8280. Game of Strings | light_ink_dots# | WA | 6ms | 13088kb | C++20 | 2.0kb | 2024-05-09 19:03:09 | 2024-05-09 19:03:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,q;
const int N=2e6+100;
char s[N];
const int M=N;
int ch[M][27],f[M],l[M],cnt,now,pos[N];
inline int clone(int q){
int z=++cnt;memcpy(ch[z],ch[q],sizeof(ch[q]));
f[z]=f[q];return z;
}
inline void ins(int c,int i){
int p=now,np=++cnt;now=cnt;pos[i]=cnt;
l[np]=l[p]+1;
while(p&&ch[p][c]==0) ch[p][c]=np,p=f[p];
if(!p){f[np]=1;return ;}
int q=ch[p][c];
if(l[q]==l[p]+1){f[np]=q;return ;}
int nq=clone(q);f[np]=f[q]=nq;l[nq]=l[p]+1;
while(p&&ch[p][c]==q) ch[p][c]=nq,p=f[p];
}
struct BIT{
int t[N];
void ins(int x,int w){
for(int i=x;i<=cnt;i+=(i&(-i))) t[i]+=w;
}
int ask(int x){
int ans=0;
for(int i=x;i>0;i-=(i&(-i))) ans+=t[i];
return ans;
}
int ask(int x,int y){
return ask(y)-ask(x-1);
}
}T;
vector<int>v[N];
int dfn[N],siz[N],step;
void dfs(int x){
dfn[x]=++step;siz[x]=1;
for(auto y:v[x]){
dfs(y);siz[x]+=siz[y];
}
}
int dp[N],argg[N];
int occ(int l,int r){
int u=1;
for(int i=l;i<=r;i++)
u=ch[u][s[i]-'a'];
return T.ask(dfn[u],dfn[u]+siz[u]-1);
}
int main(){
ios::sync_with_stdio(false);
memset(dp,-63,sizeof(dp));
cin>>s,n=strlen(s);
for(int i=n;i>=1;i--)
s[i]=s[i-1];
cnt=now=1;
for(int i=n;i>=1;i--){
ins(s[i]-'a',i);
}
for(int i=2;i<=cnt;i++) v[f[i]].push_back(i);
dfs(1);
// BF
argg[n]=n,dp[n]=1;dp[n+1]=0;
T.ins(dfn[pos[n]],1);
for(int i=n-1;i>=1;i--){
T.ins(dfn[pos[i]],1);
for(int j=i+1;j<=i+1;j++){
int tmp=occ(i,j-1)-dp[j];
if(tmp>dp[i]) dp[i]=tmp,argg[i]=j;
}
for(int j=argg[i+1];j<=argg[i+1]+10&&j<=n;j++){
int tmp=occ(i,j-1)-dp[j];
if(tmp>dp[i]) dp[i]=tmp,argg[i]=j;
}
// if(argg[i]!=i+1) cerr<<">>";
// cerr<<i<<" "<<argg[i]<<" "<<dp[i]<<endl;
}
cout<<dp[1];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 13088kb
input:
abbabbbbabbaaaaabbbaabaaaaaabbbaabbabababaabababaababaaaaaabaaabaaabbbbababaaabbbabababbbabbbaabaaababbbaabaabbaaabbababaaaaabbbaabaaabbaabaabaaabaaabaababaabbbbbbbbabbbbbabbbaabababbaababbbbbabbbbaaabbaabaabaaabbabbaaabbaaababaabbbaabbbaaaabbababbabaababababaaaabbaaaabaabaaaababaaabababbbaaabababbb...
output:
1280
result:
wrong answer 1st lines differ - expected: '1281', found: '1280'