AT2162
Lithium_Chestnut · · 题解
首先简化一下这题的题意,很显然就是给你两个长度为
如上图,圈内的代表重合部分,显然新串的长度就是
求
那么至此,就大功告成了,时间复杂度
代码:
#include<bits/stdc++.h>
using namespace std;
string a,b;
int n,same;
int read()
{
int x=0,w=0;
char ch=0;
while(!isdigit(ch))
{
w|=ch=='-';
ch=getchar();
}
while(isdigit(ch))
{
x=(x<<3)+(x<<1)+(ch^48);
ch=getchar();
}
return w?-x:x;
}
void write(int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9) write(x/10);
putchar(x%10+'0');
return;
}
int main()
{
n=read();
cin>>a>>b;
for(int i=0;i<n;i++)
{
if(a[i]==b[same]) same++;
}
write(n*2-same);
return 0;
}