Language: C++

#include <algorithm>
#include <iostream>

#define _For(idx, from, to, inc, cmp) \
	for(auto idx=(from) ; idx cmp (to) ; inc idx)
#define ForLE(idx, from, to) \
	_For(idx, from, to, ++, <=)
#define ForGE(idx, from, to) \
	_For(idx, from, to, --, >=)
#define ForLT(idx, from, to) \
	_For(idx, from, to, ++, <)
#define ForGT(idx, from, to) \
	_For(idx, from, to, --, >)
#define For(idx, from, to) \
	_For(idx, from, to, ++, <)

void DisableIOSync() {
	std::cin.tie(0);
	std::cout.tie(0);
	std::ios::sync_with_stdio(false);
}

using IV = std::vector<int>;
struct Score {
	uint64_t	score;
	bool		bFound;

	Score() = default;
	Score(uint64_t sc, bool bf):
		score(sc),
		bFound(bf)
	{}
	uint64_t value() const {
		return score | (bFound ? 0 : (uint64_t(1)<<63));
	}
	static Score GetMin(const Score& s0, const Score& s1) {
		if(s0.value() < s1.value())
			return s0;
		return s1;
	}
};
constexpr int NChar = 'z'-'a'+1;
Score BFS(const IV (&pos)[NChar], const int ofs, const uint64_t cur, const int depth, const Score& best) {
	if(depth < 0)
		return {cur, false};

	Score ret = best;
	For(i, 0, NChar) {
		auto& ps = pos[i];
		auto itr = std::lower_bound(ps.begin(), ps.end(), ofs);
		if(itr == ps.end()) {
			ret = Score::GetMin(ret, Score((cur<<8) + i+1, true));
		} else {
			auto nextsc = (cur<<8)+i+1;
			if(Score(nextsc, false).value() < best.value()) {
				const auto lr = BFS(pos, *itr+1, nextsc, depth-1, ret);
				ret = Score::GetMin(ret, lr);
			}
		}
	}
	return ret;
}
std::string NumToStr(uint64_t num) {
	std::string s;
	while(num != 0) {
		s.push_back((num & 0xff) + 'a' - 1);
		num >>= 8;
	}
	std::reverse(s.begin(), s.end());
	return s;
}
int main() {
	DisableIOSync();

	IV	pos[NChar];
	std::string str;
	std::getline(std::cin, str);
	const int Len = str.length();
	For(i, 0, Len) {
		const int idx = str[i] - 'a';
		pos[idx].push_back(i);
	}
	Score res;
	int depth = 0;
	for(;;) {
		res = BFS(pos, 0, 0, depth, Score(std::numeric_limits<uint64_t>::max(), false));
		if(res.bFound)
			break;
		++depth;
	}
	std::cout << std::hex << NumToStr(res.score) << std::endl;
	return 0;
}


Compiler output:
a.cc:23:17: error: 'vector' in namespace 'std' does not name a template type
   23 | using IV = std::vector<int>;
      |                 ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <iostream>
  +++ |+#include <vector>
    3 | 
a.cc:25:9: error: 'uint64_t' does not name a type
   25 |         uint64_t        score;
      |         ^~~~~~~~
a.cc:3:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    2 | #include <iostream>
  +++ |+#include <cstdint>
    3 | 
a.cc:29:23: error: expected ')' before 'sc'
   29 |         Score(uint64_t sc, bool bf):
      |              ~        ^~~
      |                       )
a.cc:33:9: error: 'uint64_t' does not name a type
   33 |         uint64_t value() const {
      |         ^~~~~~~~
a.cc:33:9: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc: In static member function 'static Score Score::GetMin(const Score&, const Score&)':
a.cc:37:23: error: 'const struct Score' has no member named 'value'
   37 |                 if(s0.value() < s1.value())
      |                       ^~~~~
a.cc:37:36: error: 'const struct Score' has no member named 'value'
   37 |                 if(s0.value() < s1.value())
      |                                    ^~~~~
a.cc: At global scope:
a.cc:43:17: error: ISO C++ forbids declaration of 'IV' with no type [-fpermissive]
   43 | Score BFS(const IV (&pos)[NChar], const int ofs, const uint64_t cur, const int depth, const Score& best) {
      |                 ^~
a.cc:43:20: error: expected ',' or '...' before '(' token
   43 | Score BFS(const IV (&pos)[NChar], const int ofs, const uint64_t cur, const int depth, const Score& best) {
      |                    ^
a.cc: In function 'Score BFS(int)':
a.cc:44:12: error: 'depth' was not declared in this scope
   44 |         if(depth < 0)
      |            ^~~~~
a.cc:45:25: error: 'cur' was not declared in this scope
   45 |                 return {cur, false};
      |                         ^~~
a.cc:45:35: error: could not convert '{<expression error>, false}' from '<brace-enclosed initializer list>' to 'Score'
   45 |                 return {cur, false};
      |                                   ^
      |                                   |
      |                                   <brace-enclosed initializer list>
a.cc:47:21: error: 'best' was not declared in this scope
   47 |         Score ret = best;
      |                     ^~~~
a.cc:49:28: error: 'pos' was not declared in this scope; did you mean 'ps'?
   49 |                 auto& ps = pos[i];
      |                            ^~~
      |                            ps
a.cc:50:67: error: 'ofs' was not declared in this scope
   50 |                 auto itr = std::lower_bound(ps.begin(), ps.end(), ofs);
      |                                                                   ^~~
a.cc:52:57: error: 'cur' was not declared in this scope
   52 |                         ret = Score::GetMin(ret, Score((cur<<8) + i+1, true));
      |                                                         ^~~
a.cc:54:40: error: 'cur' was not declared in this scope
   54 |                         auto nextsc = (cur<<8)+i+1;
      |                                        ^~~
a.cc:56:74: error: 'depth' was not declared in this scope
   56 |                                 const auto lr = BFS(pos, *itr+1, nextsc, depth-1, ret);
      |                                                                          ^~~~~
a.cc: At global scope:
a.cc:63:22: error: 'uint64_t' was not declared in this scope
   63 | std::string NumToStr(uint64_t num) {
      |                      ^~~~~~~~
a.cc:63:22: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:63:36: error: expected ',' or ';' before '{' token
   63 | std::string NumToStr(uint64_t num) {
      |                                    ^
a.cc: In function 'int main()':
a.cc:75:9: error: 'IV' was not declared in this scope
   75 |         IV      pos[NChar];
      |         ^~
a.cc:81:17: error: 'pos' was not declared in this scope
   81 |                 pos[idx].push_back(i);
      |                 ^~~
a.cc:86:27: error: 'pos' was not declared in this scope
   86 |                 res = BFS(pos, 0, 0, depth, Score(std::numeric_limits<uint64_t>::max(), false));
      |                           ^~~
a.cc:86:56: error: 'numeric_limits' is not a member of 'std'
   86 |                 res = BFS(pos, 0, 0, depth, Score(std::numeric_limits<uint64_t>::max(), false));
      |                                                        ^~~~~~~~~~~~~~
a.cc:86:71: error: 'uint64_t' was not declared in this scope
   86 |                 res = BFS(pos, 0, 0, depth, Score(std::numeric_limits<uint64_t>::max(), false));
      |                                                                       ^~~~~~~~
a.cc:86:71: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:86:82: error: '::max' has not been declared; did you mean 'std::max'?
   86 |                 res = BFS(pos, 0, 0, depth, Score(std::numeric_limits<uint64_t>::max(), false));
      |                                                                                  ^~~
      |                                                                                  std::max
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:91:47: error: 'struct Score' has no member named 'score'; did you mean 'Score'?
   91 |         std::cout << std::hex << NumToStr(res.score) << std::endl;
      |                                               ^~~~~
      |                                               Score