Language: C++

#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=200005;
int n,end=INF;
char c[maxn];
string s;
int nxt[maxn][30],dp[maxn],prev[maxn];
vector<char>ans;

int MIN(int a,int b){
	if(a>=n)return b;
	if(b>=n)return a;
	vector<int>A,B;
	int cur=a;
	A.push_back(a);
	while(prev[cur]!=INF)A.push_back(prev[cur]),cur=prev[cur];
	cur=b;
	B.push_back(b);
	while(prev[cur]!=INF)B.push_back(prev[cur]),cur=prev[cur];
	for(int i=A.size()-1;i>=0;i--)if(s[A[i]]!=s[B[i]]){
		return s[A[i]]<s[B[i]]?a:b;
	}
	return a;
}

int main(){
	scanf("%s",c);
	s=c;
	n=s.size();
	rep(i,26)nxt[n][i]=n;
	for(int i=n-1;i>=0;i--)rep(j,26){
		if(s[i]-'a'==j)nxt[i][j]=i;
		else nxt[i][j]=nxt[i+1][j];
	}
	rep(i,maxn)dp[i]=prev[i]=INF;
	rep(i,26){
		dp[nxt[0][i]]=0;
		if(nxt[0][i]==n)end=min(end,i);
	}
	rep(i,n){
		rep(j,26){
			int p=nxt[i+1][j];
//			if(i==126&&j==17)cout<<p<<endl;
			if(dp[p]>dp[i]+1){
				dp[p]=dp[i]+1;
				if(p==n)end=j;
				prev[p]=i;
			}
			else if(dp[p]==dp[i]+1){
				int tmp=MIN(prev[p],i);
				if(tmp==i){
					if(tmp==prev[p]&&p==n)end=min(end,j);
					else if(p==n)end=j;
				}
				prev[p]=tmp;
			}
		}
	}
//	cout<<"ok"<<endl;
	ans.push_back((char)(end+'a'));
	int cur=n;
	while(prev[cur]!=INF){
		ans.push_back(s[prev[cur]]);
		cur=prev[cur];
	}
	for(int i=ans.size()-1;i>=0;i--)printf("%c",ans[i]);
	return 0;
}

Compiler output:
a.cc: In function 'int MIN(int, int)':
a.cc:68:15: error: reference to 'prev' is ambiguous
   68 |         while(prev[cur]!=INF)A.push_back(prev[cur]),cur=prev[cur];
      |               ^~~~
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:2:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:59:28: note:                 'int prev [200005]'
   59 | int nxt[maxn][30],dp[maxn],prev[maxn];
      |                            ^~~~
a.cc:68:42: error: reference to 'prev' is ambiguous
   68 |         while(prev[cur]!=INF)A.push_back(prev[cur]),cur=prev[cur];
      |                                          ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:59:28: note:                 'int prev [200005]'
   59 | int nxt[maxn][30],dp[maxn],prev[maxn];
      |                            ^~~~
a.cc:68:57: error: reference to 'prev' is ambiguous
   68 |         while(prev[cur]!=INF)A.push_back(prev[cur]),cur=prev[cur];
      |                                                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:59:28: note:                 'int prev [200005]'
   59 | int nxt[maxn][30],dp[maxn],prev[maxn];
      |                            ^~~~
a.cc:71:15: error: reference to 'prev' is ambiguous
   71 |         while(prev[cur]!=INF)B.push_back(prev[cur]),cur=prev[cur];
      |               ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:59:28: note:                 'int prev [200005]'
   59 | int nxt[maxn][30],dp[maxn],prev[maxn];
      |                            ^~~~
a.cc:71:42: error: reference to 'prev' is ambiguous
   71 |         while(prev[cur]!=INF)B.push_back(prev[cur]),cur=prev[cur];
      |                                          ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:59:28: note:                 'int prev [200005]'
   59 | int nxt[maxn][30],dp[maxn],prev[maxn];
      |                            ^~~~
a.cc:71:57: error: reference to 'prev' is ambiguous
   71 |         while(prev[cur]!=INF)B.push_back(prev[cur]),cur=prev[cur];
      |                                                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:59:28: note:                 'int prev [200005]'
   59 | int nxt[maxn][30],dp[maxn],prev[maxn];
      |                            ^~~~
a.cc: In function 'int main()':
a.cc:87:26: error: reference to 'prev' is ambiguous
   87 |         rep(i,maxn)dp[i]=prev[i]=INF;
      |                          ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:59:28: note:                 'int prev [200005]'
   59 | int nxt[maxn][30],dp[maxn],prev[maxn];
      |                            ^~~~
a.cc:90:33: error: reference to 'end' is ambiguous
   90 |                 if(nxt[0][i]==n)end=min(end,i);
      |                                 ^~~
In file included from /usr/include/c++/14/string:53:
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/range_access.h:36:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:56:7: note:                 'int end'
   56 | int n,end=INF;
      |       ^~~
a.cc:90:41: error: reference to 'end' is ambiguous
   90 |                 if(nxt[0][i]==n)end=min(end,i);
      |                                         ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:56:7: note:                 'int end'
   56 | int n,end=INF;
      |       ^~~
a.cc:98:41: error: reference to 'end' is ambiguous
   98 |                                 if(p==n)end=j;
      |                                         ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:56:7: note:                 'int end'
   56 | int n,end=INF;
      |       ^~~
a.cc:99:33: error: reference to 'prev' is ambiguous
   99 |                                 prev[p]=i;
      |                                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename