Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
using namespace std;
#define N 210000
int n,i,a[N],j,last[30],ans[N],dp[N],next[N][30];
char s[N];
int main()
{
	scanf("%s",s);
	n=strlen(s);
	for (i=1;i<=n;i++)
	a[i]=s[i-1]-'a'+1;
	for (i=1;i<=26;i++) last[i]=n+1;
	for (i=n;i>=1;i--)
	{
		last[a[i]]=i;
		for (j=1;j<=26;j++) next[i][j]=last[j];
	}
	for (i=1;i<=n+1;i++) dp[i]=10000000;
	for (i=n;i>=1;i--)
	{
		for (j=1;j<=26;j++)
		{
			if (dp[next[i][j]+1]+1<dp[i])
			dp[i]=dp[next[i][j]+1]+1,ans[i]=j;
		}
	}
	//printf("%d\n",dp[1]);
	int now=1;
	while (now<=n)
	{
		printf("%c",ans[now]+'a'-1);
		now=next[now][ans[now]]+1;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:37: error: reference to 'next' is ambiguous
   25 |                 for (j=1;j<=26;j++) next[i][j]=last[j];
      |                                     ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:38: note:                 'int next [210000][30]'
   13 | int n,i,a[N],j,last[30],ans[N],dp[N],next[N][30];
      |                                      ^~~~
a.cc:32:32: error: reference to 'next' is ambiguous
   32 |                         if (dp[next[i][j]+1]+1<dp[i])
      |                                ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:38: note:                 'int next [210000][30]'
   13 | int n,i,a[N],j,last[30],ans[N],dp[N],next[N][30];
      |                                      ^~~~
a.cc:33:34: error: reference to 'next' is ambiguous
   33 |                         dp[i]=dp[next[i][j]+1]+1,ans[i]=j;
      |                                  ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:38: note:                 'int next [210000][30]'
   13 | int n,i,a[N],j,last[30],ans[N],dp[N],next[N][30];
      |                                      ^~~~
a.cc:41:21: error: reference to 'next' is ambiguous
   41 |                 now=next[now][ans[now]]+1;
      |                     ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:38: note:                 'int next [210000][30]'
   13 | int n,i,a[N],j,last[30],ans[N],dp[N],next[N][30];
      |                                      ^~~~