1 条题解
-
0
C++ :
#include<iostream> #include<cstdio> #include<algorithm> #include<vector> #include<cstdlib> #include<cmath> #include<cstring> #include<map> using namespace std; #define maxn 100100 #define llg long long #define inf (llg)1e16 #define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); llg n,m,ans,sum,g[maxn],f[maxn]; llg lena,lenb,lenc,a[maxn],b[maxn],c[maxn],s[maxn]; vector<llg>p[20000000]; void get_(llg *a,llg &n) { llg x=0; char ch=getchar(); for (; ch!='\n'; ch=getchar()) if (ch>='a' && ch<='z') x=x*27+ch-'a'+1; else if (x){ a[++n]=x; x=0; } if (x) a[++n]=x; } int main() { // yyj("ti"); get_(s,n); get_(a,lena); get_(b,lenb); get_(c,lenc); llg l=0,r=n+1; for (llg i=1;i<=lena;i++) { l++; while (a[i]!=s[l]) l++,sum++; } for (llg i=lenc;i>=1;i--) { r--; while (s[r]!=c[i]) r--,sum++; } l++; r--; for (llg i=1;i<=lenb;i++) p[b[i]].push_back(i); for (llg i=0;i<=lenb;i++) g[i]=inf; ans=inf; for (llg i=l;i<=r;i++) { llg w=p[s[i]].size(); for (llg k=w-1;k>=0;k--) { llg x=p[s[i]][k]; if (x==0) continue; if (x==1) {f[1]=i; g[1]=0;} else { if (f[x-1]) { f[x]=i; g[x]=g[x-1]+i-f[x-1]-1; } } ans=min(ans,g[lenb]); } } cout<<ans+sum; return 0; }
- 1
信息
- ID
- 971
- 时间
- 5000ms
- 内存
- 512MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者