Wa on #4 求助!悬关
查看原帖
Wa on #4 求助!悬关
678447
CSPAK_Zhangxiuqi0011楼主2024/8/17 19:40

rt 提交记录

#include<bits/stdc++.h>
using namespace std;
#define int long long
string a,b,c,h;
int nxt[100005];
int work(string x,string y,string z) {
	int lx,ly,lz,lh;
	lx = x.size()-1;
	ly = y.size()-1;
	lz = z.size()-1;
	h = " ";
	lh = 0;
	for(int i = 1; i<lx; i++) {
		h+=x[i];
		lh++;
	}
	int j,ans;
	j = 0;
	for(int i = 2; i<=ly; i++) {
		while(j && y[j+1]!=y[i]) {
			j = nxt[j];
		}
		if(y[j+1] == y[i]) {
			j++;
		}
		nxt[i] = j;
	}
	j = 0;
	ans = 0;
	for(int i = 1; i<=lh; i++) {
		while(j && y[j+1]!=h[i]) {
			j = nxt[j];
		}
		if(y[j+1] == h[i]) {
			j++;
		}
		ans = max(ans,j);
		if(j == ly) {
			ans = j;
			break;
		}
	}
	for(int i = ans+1; i<ly; i++) {
		h+=y[i];
		lh++;
	}
	for(int i = 1; i<=ly; i++) {
		nxt[i] = 0;
	}
	j = 0;
	for(int i = 2; i<=lz; i++) {
		while(j && z[j+1]!=z[i]) {
			j = nxt[j];
		}
		if(z[j+1] == z[i]) {
			j++;
		}
		nxt[i] = j;
	}
	j = 0;
	ans = 0;
	for(int i = 1; i<=lh; i++) {
		while(j && z[j+1]!=h[i]) {
			j = nxt[j];
		}
		if(z[j+1] == h[i]) {
			j++;
		}
		ans = max(ans,j);
		if(j == lz) {
			ans = j;
			break;
		}
	}
	for(int i = ans+1; i<lz; i++) {
		h+=z[i];
		lh++;
	}
	for(int i = 1; i<=lz; i++) {
		nxt[i] = 0;
	}
	return lh;
}
signed main() {
	cin>>a>>b>>c;
	a = " "+a+" ";
	b = " "+b+" ";
	c = " "+c+" ";
	cout<<min(min(min(min(min(work(a,b,c),work(a,c,b)),work(b,a,c)),work(b,c,a)),work(c,a,b)),work(c,b,a))<<"\n";
	return 0;
}

/*这是#5  不要管他
ujgquqxdlowuwnqkmbd
wdwkhkdgsujgqu
jlxqvcuivagmw

40
*/
/*
jlxqvcuivagmwdwkhkdgsujgquqxdlowuwnqkmbd
*/
2024/8/17 19:40
加载中...