Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


vector<int> argmin_subseq(const vector<int> &seq,const int K){
  vector<int> A=seq;
  const int mi=numeric_limits<int>::min();
  int N=A.size(),mx=mi,amx;
  assert(0<K && K<=N);
  vector<int> idx,nx;
  for(auto &I:A){I*=-1;}
  for(int i=0;i+K<=N;i++){mx=max(mx,A[i]);}
  for(auto &I:A){I-=mx-1;}
  for(int i=0;i+K<=N;i++){
    if(A[i]==1){idx.push_back(i);}
  }
  for(int len=1;len<K;){
    mx=mi;
    amx=-1;
    for(auto I:idx){
      if(mx<=A[I+len]){
        mx=A[I+len];
        amx=I;
      }
    }
    if(mx<=0){
      for(auto I:idx){
        if(A[I+len]==mx){A[I]++; nx.push_back(I);}
      }
      len++;
    }
    else{
      int ls=idx.back();
      if(ls+len+K>N){
        for(int j=0;j<mx && len+j<K;j++){
          if(seq[amx+len+j]>seq[ls+len+j]){return {ls};}
          else if(seq[amx+len+j]==seq[ls+len+j]){A[ls]++;}
          else{break;}
        }
      }
      reverse(idx.begin(),idx.end());
      for(auto I:idx){
        A[I]+=max(0,min(A[I+len],K-len));
        mx=max(mx,A[I]);
      }
      reverse(idx.begin(),idx.end());
      for(auto I:idx){
        if(A[I]==mx){nx.push_back(I);}
      }
      len=mx;
    }
    idx.clear();
    swap(nx,idx);
  }
  return idx;
}

vector<int> argmin2(string s,int N){
  vector<int> ret;
  string mi=s.substr(0,N);
  for(int i=1;i<=N;i++){mi=min(mi,s.substr(i,N));}
  for(int i=0;i<=N;i++){
    if(mi==s.substr(i,N)){ret.push_back(i);}
  }
  return ret;
}

int main(){
  ll N,K;
  cin>>N>>K;
  string s;
  cin>>s;
  string t=s;
  reverse(t.begin(),t.end());
  s+=t;
  vector<int> A(s.size());
  for(int i=0;i<(int)s.size();i++){A[i]=(int)s[i];}
  vector<int> ret=argmin_subseq(A,N);
  vector<int> ret2=argmin2(s,N);
  assert(ret.size()<=ret2);
  int idx=ret[0];
  int cnt=0,c=0;
  for(int i=0;i<N;i++){
    if(A[idx]==A[idx+i]){cnt++;}
    else{break;}
  }
  c=cnt;
  while(K>1 && cnt<N){cnt*=2; K--;}
  string ans;
  for(int i=0;i<cnt && i<N;i++){ans+=s[idx];}
  for(int i=cnt;i<N;i++){ans+=s[idx+c+(i-cnt)];}
  cout<<ans<<endl;

  
  return 0;
}


Compiler output:
In file included from /usr/include/c++/14/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:106,
                 from a.cc:1:
a.cc: In function 'int main()':
a.cc:94:20: error: no match for 'operator<=' (operand types are 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'std::vector<int>')
   94 |   assert(ret.size()<=ret2);
      |          ~~~~~~~~~~^~~~~~
      |                  |   |
      |                  |   std::vector<int>
      |                  std::vector<int>::size_type {aka long unsigned int}
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:1154:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator<=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1154 |     operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1154:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/regex.h:1260:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator<=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1260 |     operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1260:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/regex.h:1353:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator<=(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1353 |     operator<=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1353:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/regex.h:1427:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<=(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
 1427 |     operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1427:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   'std::vector<int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/regex.h:1521:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1521 |     operator<=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1521:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/regex.h:1599:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<=(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)'
 1599 |     operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1599:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   'std::vector<int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/regex.h:1699:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1699 |     operator<=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1699:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1064:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1064 |     operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1064:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::pair<_T1, _T2>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:469:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  469 |     operator<=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:469:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/stl_iterator.h:513:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  513 |     operator<=(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:513:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/stl_iterator.h:1704:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1704 |     operator<=(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1704:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/stl_iterator.h:1767:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1767 |     operator<=(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1767:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'std::vector<int>::size_type' {aka 'long unsigned int'}
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
In file included from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/string_view:717:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<=(basic_string_view<_CharT, _Traits>, basic_string_view<_CharT, _Traits>)'
  717 |     operator<=(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:717:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'std::basic_string_view<_CharT, _Traits>' and 'long unsigned int'
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/string_view:724:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<=(basic_string_view<_CharT, _Traits>, __type_identity_t<basic_string_view<_CharT, _Traits> >)'
  724 |     operator<=(basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:724:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   mismatched types 'std::basic_string_view<_CharT, _Traits>' and 'long unsigned int'
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/string_view:732:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<=(__type_identity_t<basic_string_view<_CharT, _Traits> >, basic_string_view<_CharT, _Traits>)'
  732 |     operator<=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
      |     ^~~~~~~~
/usr/include/c++/14/string_view:732:5: note:   template argument deduction/substitution failed:
a.cc:94:22: note:   'std::vector<int>' is not derived from 'std::basic_string_view<_CharT, _Traits>'
   94 |   assert(ret.size()<=ret2);
      |                      ^~~~
/usr/include/c++/14/bits/basic_string.h:3956:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<=(const __cxx11::basic_string<_CharT, _Traits,