Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <chrono>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
inline bool chmax(T &a, T b) { return a < b && (a = b, true); }

int dp[5010][5010];

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	auto start = chrono::system_clock::now();
	auto split = chrono::system_clock::now();

	int N;
	cin >> N;
	string s;
	cin >> s;

	auto check = [&](int cut) {
		int res = 0;
		fill(dp, dp + 5010 + 1, vector<int>(5010));
		for (int i = 0; i < cut; i++) {
			for (int j = cut; j < N; j++) {
				if (s[i] == s[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
				chmax(res, dp[i + 1][j + 1]);
			}
		}
		return res;
	};

	// 3分探索
	int lb = 0, ub = N, ans = 0;
	while (chrono::duration_cast<chrono::milliseconds>(split-start).count() < 1920) {

		int t1 = (2.5 * lb + ub) / 3.5;
		int t2 = ceil((lb + 2.5 * ub) / 3.5);

		int c1 = check(t1);
		int c2 = check(t2);
		if (c1 < c2) lb = t1;
		else ub = t2;

		chmax(ans, max(c1, c2));
		split = chrono::system_clock::now();
	}

	DMP(ub, lb);
	cout << ans << "\n";

	return 0;
}


Compiler output:
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<(! std::__is_scalar<_Tp>::__value), void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[5010]; _Tp = vector<int>; typename __gnu_cxx::__enable_if<(! __is_scalar<_Tp>::__value), void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int (*)[5010]; _Tp = vector<int>]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[5010]; _Tp = vector<int>]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:59:7:   required from here
   59 |                 fill(dp, dp + 5010 + 1, vector<int>(5010));
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:940:18: error: incompatible types in assignment of 'const std::vector<int>' to 'int [5010]'
  940 |         *__first = __value;
      |         ~~~~~~~~~^~~~~~~~~