Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
30343 | A21μΘ_wjy | 【S】T4 | C++ | 运行出错 | 0 | 0 MS | 260 KB | 815 | 2024-06-23 18:38:37 |
#include<bits/stdc++.h> #define int long long using namespace std; string A,B,P; vector<int> GetBD(string s){ int L=s.length(); vector<int> BD(L); BD[0]=0; for(int i=1;i<L;i++){ int t=BD[i-1]; while(s[i]!=s[t]&&t)t=BD[t-1]; if(s[i]==s[t])t++; BD[i]=t; } return BD; } int KMP(string S,string T){ string G=T+"#"+S; int L=T.length(); int N=G.length(); vector<int> BD=GetBD(G); int cnt=0; for(int i=L;i<N;i++){ if(BD[i]==L)cnt++; } return cnt; } signed main(){ freopen("string.in","r",stdin); freopen("string.out","w",stdout); cin>>A>>B>>P; int L=A.length(); int ans=0,cnt=0; for(int i=0;i<=L;i++){ string Cur=(A.substr(0,i-1)+B+A.substr(i,L-1)); int K=KMP(Cur,P); if(K>ans)ans=K,cnt=1; else if(K==ans)cnt++; } cout<<ans<<" "<<cnt<<endl; }