Language: C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    size_t N;
    cin >> N;

    vector<size_t> A(3 * N);
    for (size_t &a : A)
    {
        cin >> a;
    }
    if (N == 1)
    {
        if (A[0] == A[1] && A[1] == A[2])
        {
            cout << 1 << endl;
        }
        else
        {
            cout << 0 << endl;
        }
        return 0;
    }

    vector<vector<vector<int>>> dp(2, vector<vector<int>>(2005, vector<int>(2005, -1)));
    queue<pair<size_t, size_t>> q;
    for (size_t i = 0; i < 5; i++)
    {
        for (size_t j = i + 1; j < 5; j++)
        {
            set<size_t> s;
            for (size_t k = 0; k < 5; k++)
            {
                if (k == i)
                {
                    continue;
                }
                if (k == j)
                {
                    continue;
                }
                s.insert(A[k]);
            }
            if (s.size() == 1)
            {
                if (dp[0][A[i]][A[j]] < 1)
                {
                    dp[0][A[i]][A[j]] = 1;
                    q.push(make_pair(A[i], A[j]));
                }
            }
            else
            {
                if (dp[0][A[i]][A[j]] < 0)
                {
                    dp[0][A[i]][A[j]] = 0;
                    q.push(make_pair(A[i], A[j]));
                }
            }
        }
    }

    for (size_t i = 1; i < min(N - 1, 100); i++)
    // for (size_t i = 1; i < N - 1; i++)
    {
        queue<pair<size_t, size_t>> tmp;
        while (!q.empty())
        {
            vector<size_t> five(5);
            five[0] = q.front().first;
            five[1] = q.front().second;
            five[2] = A[3 * i + 2];
            five[3] = A[3 * i + 3];
            five[4] = A[3 * i + 4];
            q.pop();
            for (size_t j = 0; j < 5; j++)
            {
                for (size_t k = j + 1; k < 5; k++)
                {
                    set<size_t> s;
                    for (size_t l = 0; l < 5; l++)
                    {
                        if (l == j)
                        {
                            continue;
                        }
                        if (l == k)
                        {
                            continue;
                        }
                        s.insert(five[l]);
                    }
                    if (s.size() == 1)
                    {
                        if (dp[1][five[i]][five[j]] < dp[0][five[0]][five[1]] + 1)
                        {
                            dp[1][five[i]][five[j]] = dp[0][five[0]][five[1]] + 1;
                            tmp.push(make_pair(five[i], five[j]));
                        }
                    }
                    else
                    {
                        if (dp[1][five[i]][five[j]] < dp[0][five[0]][five[1]])
                        {
                            dp[1][five[i]][five[j]] = dp[0][five[0]][five[1]];
                            tmp.push(make_pair(five[i], five[j]));
                        }
                    }
                }
            }
        }
        q = tmp;
        dp[0] = dp[1];
        dp[1] = vector<vector<int>>(2005, vector<int>(2005, -1));
    }
    // int ans = 0;
    // while (!q.empty())
    // {
    //     set<size_t> s;
    //     s.insert(q.front().first);
    //     s.insert(q.front().second);
    //     s.insert(A.back());
    //     if (s.size() == 1)
    //     {
    //         ans = max(ans, dp[0][q.front().first][q.front().second] + 1);
    //     }
    //     else
    //     {
    //         ans = max(ans, dp[0][q.front().first][q.front().second]);
    //     }
    //     q.pop();
    // }
    // cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:31: error: no matching function for call to 'min(size_t, int)'
   65 |     for (size_t i = 1; i < min(N - 1, 100); i++)
      |                            ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:65:31: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   65 |     for (size_t i = 1; i < min(N - 1, 100); i++)
      |                            ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:65:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   65 |     for (size_t i = 1; i < min(N - 1, 100); i++)
      |                            ~~~^~~~~~~~~~~~