Cod sursa(job #3149115)

Utilizator Alex_BerbescuBerbescu Alexandru Alex_Berbescu Data 6 septembrie 2023 14:40:27
Problema Cutii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define dim 3505
using namespace std;
struct box
{
    int x, y, z;
} v[dim];
int test_cases, n, maxi;
int best[dim];
bool compare(box a, box b)
{
    return a.z < b.z;
}
bool verif(box a, box b)
{
    return (a.x < b.x && a.y < b.y && a.z < b.z);
}
ifstream fin("cutii.in");
ofstream fout("cutii.out");
int32_t main(int argc, char * argv[])
{
    fin >> n >> test_cases;
    while(test_cases--)
    {
        maxi = 0;
        memset(best, 0, sizeof best);
        for(int i = 1; i <= n; ++i)
        {
            fin >> v[i].x >> v[i].y >> v[i].z;
        }
        sort(v + 1, v + n + 1, compare);
        best[1] = 1;
        maxi = 1;
        for(int i = 2; i <= n; ++i)
        {
            for(int j = i - 1; j >= 1; --j)
            {
                best[i] = 1;
                if(verif(v[j], v[i]) && best[j] + 1 > best[i])
                {
                    best[i] = best[j] + 1;
                    maxi = max(best[i], maxi);
                }
            }
        }
        fout << maxi << '\n';
    }
    return 0;
}