Language: C++

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
  size_t N;
  std::string S;
  std::cin >> N >> S;

  // 共通文字列の最大長を求める
  size_t result = 0;  // 一致する部分文字列の最大長
  std::vector<size_t> z;  // [0, z[i])と[i, i+z[i])が一致している
  for (size_t l1 = 0; l1 < N - 1; ++l1) {
    // バッファをクリアする
    z.clear();
    z.resize(N - l1, 0);

    //// Z-Algorithm
    //size_t c = 0;  // [l1, l1+len)と[c, z[c])が一致している
    //for (size_t i = 1; i < z.size(); ++i) {
    //  if (i + z[i - c] < c + z[c]) {
    //    // 一致を確認した範囲の中であれば、以前に計算した値を再利用できる
    //    z[i] = z[i - c];
    //  } else {
    //    // 一致を確認した範囲を外れる場合、改めて一致する部分を探す
    //    const size_t l2 = l1 + i;
    //    size_t len = c + z[c] - i;
    //    for (; l2 + len < N; ++len) {
    //      if (S[l1 + len] != S[l2 + len]) break;
    //    }
    //    z[i] = len;
    //    c = i;
    //  }
    //}
    //z[0] = z.size();

    // from #7518554
    size_t c=0,n=S.size();
    z.resize(n,0);
    for(size_t i=1;i<n;++i){
        size_t l=i-c;
        if(i+z[l]<c+z[c]) z[i]=z[l];
        else{
            size_t j=std::max(0u,c+z[c]-i);
            for(;i+j<n&&S[l1+j]==S[l1+i+j];++j);
            z[i]=j;c=i;
        }
    }
    z[0]=n;

    for(size_t j = 0; j < n-l1; ++j) result=std::max(result,std::min(j,z[j]));

    //for (size_t i = 0; i < z.size(); ++i) {
    //  result = std::max(result, std::min(i, z[i]));
    //}
  }

  std::cout << result;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:45:30: error: no matching function for call to 'max(unsigned int, size_t)'
   45 |             size_t j=std::max(0u,c+z[c]-i);
      |                      ~~~~~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:45:30: note:   deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'size_t' {aka 'long unsigned int'})
   45 |             size_t j=std::max(0u,c+z[c]-i);
      |                      ~~~~~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:45:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
   45 |             size_t j=std::max(0u,c+z[c]-i);
      |                      ~~~~~~~~^~~~~~~~~~~~~