QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#610981 | #2273. Suffixes may Contain Prefixes | ucup-team4153# | RE | 0ms | 0kb | C++20 | 1.8kb | 2024-10-04 18:33:51 | 2024-10-04 18:33:52 |
answer
#include<bits/stdc++.h>
using namespace std;using ld=long double;using ll=long long;
using pll=pair<ll,ll>;using pii=pair<int,int>;
const int M=1e9+7,P=26;const ld eps=1e-8,pi=acos(-1);const ll inf=1e17;
ll tmax(ll&a,ll b){a=max(a,b);}
struct KMP
{
vector<int>nxt,sb,dep;int n;vector<vector<int>>tr;
void solve(string&s,int len)
{
n=s.length();sb.resize(n+2,0);sb[n+1]=-1;dep=nxt=sb;
tr.resize(n+1,vector<int>(P,0));for(int i=1;i<=n;i++)sb[i]=s[i-1]-'a';
nxt.resize(n+1);nxt[0]=-1;
for(int i=1,x;i<=n;i++)
{
for(x=i-1;x&&sb[nxt[x]+1]!=sb[i];x=nxt[x]);
nxt[i]=nxt[x]+1;dep[i]=dep[nxt[i]]+1;
}
for(int i=0;i<=n;i++)
{
for(int j=0;j<P;j++)
{
int x;
for(x=i;x!=-1&&sb[x+1]!=j;x=nxt[x]);
tr[i][j]=x+1;
}
}
//for(int i=0;i<=n;i++)
//{
//cout<<i<<'/'<<nxt[i]<<'/'<<dep[i]<<'\n';
//for(int j=0;j<P;j++)cout<<tr[i][j]<<".\n"[j==P-1];
//}
nxt[0]=0;vector<vector<ll>>dp(len+1,vector<ll>(n+1,-inf));dp[0][0]=0;
ll res=0;
for(int i=1;i<=len;i++)
{
for(int j=0;j<=n;j++)
{
for(int k=0;k<P;k++)
{
int x=tr[j][k];
tmax(dp[i][x],dp[i-1][j]+dep[x]);
}
}
}
for(int j=0;j<=n;j++)tmax(res,dp[len][j]);cout<<res<<'\n';
}
};
struct S
{
int n;string s;KMP A;
void ini()
{
cin>>s>>n;A.solve(s,n);
}
void solve()
{
}
};
signed main()
{
cout<<fixed<<setprecision(12);
ios::sync_with_stdio(0);cin.tie(0);
int t=1;//cin>>t;
while(t--){S SS;SS.ini();SS.solve();}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
fsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfffsfffffsfffsfsfsfffsfffssfsfffsfsfffsfffffsfffsfffssfsfffsfsfffsffssfffsfffsfffssfsfffsfsfsfsfffsfffssfsfffsfsf...