Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;


// ローリングハッシュ
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }
};


int main() { 
    int N;
    string S;
    cin >> N >> S;

    // ロリハ
    RollingHash rh(S);

    // 二分探索判定
    bool check = [&](int d) {
        for (int i = 0; i < N; ++i) {
            for (int j = i+d; j+d <= N; ++j) {
                if (S[i] != S[j]) continue;
                if (rh.get(i, i+d) == rh.get(j, j+d)) return true;
            }
        }
        return false;
    }

    // 二分探索
    int left = 0, right = N/2 + 1;
    while (right - left > 1) {
        int mid = (left + right) >> 1;
        if (check(mid)) left = mid;
        else right = mid;
    }
        
    cout << left << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:18: error: cannot convert 'main()::<lambda(int)>' to 'bool' in initialization
   49 |     bool check = [&](int d) {
      |                  ^~~~~~~~~~~~
      |                  |
      |                  main()::<lambda(int)>
   50 |         for (int i = 0; i < N; ++i) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   51 |             for (int j = i+d; j+d <= N; ++j) {
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   52 |                 if (S[i] != S[j]) continue;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   53 |                 if (rh.get(i, i+d) == rh.get(j, j+d)) return true;
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   54 |             }
      |             ~     
   55 |         }
      |         ~         
   56 |         return false;
      |         ~~~~~~~~~~~~~
   57 |     }
      |     ~             
a.cc:61:18: error: ISO C++ forbids using pointer to a function in subtraction [-fpermissive]
   61 |     while (right - left > 1) {
      |            ~~~~~~^~~~~~
a.cc:62:25: error: invalid operands of types 'std::ios_base&(std::ios_base&)' and 'std::ios_base&(std::ios_base&)' to binary 'operator+'
   62 |         int mid = (left + right) >> 1;
      |                    ~~~~ ^ ~~~~~
      |                    |      |
      |                    |      std::ios_base&(std::ios_base&)
      |                    std::ios_base&(std::ios_base&)
a.cc:63:18: error: 'check' cannot be used as a function
   63 |         if (check(mid)) left = mid;
      |             ~~~~~^~~~~
a.cc:63:30: error: assignment of function 'std::ios_base& std::left(ios_base&)'
   63 |         if (check(mid)) left = mid;
      |                         ~~~~~^~~~~
a.cc:64:20: error: assignment of function 'std::ios_base& std::right(ios_base&)'
   64 |         else right = mid;
      |              ~~~~~~^~~~~