Language: C++

#include<stdio.h>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int R=5;
string s[2100];
char in[11000];
typedef unsigned long long wolf;
wolf rj[11000];
wolf ks=1000000007;
char rd[2010][10010];
char dp[2010][10010];
char st[2010][10010];
vector<wolf> hash[2010];
wolf cur[10010];
inline bool eq(int a,int b,int c){
	int len=b-a;
//	printf("%d %d %d: %llu %llu %llu %llu\n",a,b,c,cur[b]-cur[a],hash[c][len],rj[a],hash[c][len]*rj[a]);
	if(cur[b]-cur[a]!=hash[c][len]*rj[a])return false;
	for(int i=0;i<R;i++){
		int at=rand()%len;
		if(st[c][a+at]!=s[c][at])return false;
	}
	return true;
}
inline int cmp(int a,int b){
	int left=a-1;
	int right=a+s[b].size();
	while(left+1<right){
		int M=(left+right)/2;
		if(eq(a,M+1,b)){
			left=M;
		}else right=M;
	}
	//printf("%d\n",right);
	if(right==a+s[b].size())return 0;
	if(s[b][right-a]<st[b][right])return 1;
	return -1;
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%s",in);
		s[i]=in;
	}
	rj[0]=1;
	for(int i=1;i<11000;i++)rj[i]=rj[i-1]*ks;
	rd[a][b]=1;
	for(int i=a;i;i--){
		for(int j=0;j<=b;j++){
			if(rd[i][j]&&j>=s[i-1].size()){
				rd[i-1][j-(int)(s[i-1].size())]=1;
			}
			if(rd[i][j])rd[i-1][j]=1;
		}
	}
	for(int i=0;i<a;i++){
		hash[i]=vector<wolf>(s[i].size()+1);
		wolf now=0;
		wolf tt=1;
		for(int j=0;j<s[i].size();j++){
			now+=tt*s[i][j];
			tt*=ks;
			hash[i][j+1]=now;
	//		printf("%llu ",now);
		}
	//	printf("\n");
	}
	dp[0][0]=1;
	for(int i=0;i<b;i++)st[0][i]='z';
	for(int i=0;i<a;i++){
		wolf now=0;
		wolf tt=1;
		for(int j=0;j<b;j++){
			now+=tt*st[i][j];
			tt*=ks;
			cur[j+1]=now;
		//	printf("%llu ",now);
		}
		//printf("\n");
		for(int j=0;j<=b;j++)st[i+1][j]=st[i][j];
		//printf("%s\n",st[i]);
		for(int j=0;j<=b;j++){
			if(!dp[i][j])continue;
	//		printf("%d %d\n",i,j);
			if(rd[i+1][j])dp[i+1][j]=1;
			if(j+s[i].size()<=b&&rd[i+1][j+s[i].size()]){
				int tmp=cmp(j,i);
		//		printf("%d\n",tmp);
				if(tmp>=0){
					dp[i+1][j+s[i].size()]=1;
					if(tmp){
						bool flag=false;
						for(int k=j;k<j+s[i].size();k++){
							if(s[i][k-j]!=st[i+1][k])flag=true;
							st[i+1][k]=s[i][k-j];
							if(flag&&k!=j+s[i].size()-1)dp[i+1][j+1]=0;
						}
						break;
					}
				}
			}
		}
	}
	printf("%s\n",st[a]);
}

Compiler output:
a.cc: In function 'bool eq(int, int, int)':
a.cc:20:27: error: reference to 'hash' is ambiguous
   20 |         if(cur[b]-cur[a]!=hash[c][len]*rj[a])return false;
      |                           ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from a.cc:3:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:15:14: note:                 'std::vector<long long unsigned int> hash [2010]'
   15 | vector<wolf> hash[2010];
      |              ^~~~
a.cc: In function 'int main()':
a.cc:60:17: error: reference to 'hash' is ambiguous
   60 |                 hash[i]=vector<wolf>(s[i].size()+1);
      |                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:15:14: note:                 'std::vector<long long unsigned int> hash [2010]'
   15 | vector<wolf> hash[2010];
      |              ^~~~
a.cc:66:25: error: reference to 'hash' is ambiguous
   66 |                         hash[i][j+1]=now;
      |                         ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:15:14: note:                 'std::vector<long long unsigned int> hash [2010]'
   15 | vector<wolf> hash[2010];
      |              ^~~~