Cod sursa(job #3149117)

Utilizator Alex_BerbescuBerbescu Alexandru Alex_Berbescu Data 6 septembrie 2023 14:44:42
Problema Cutii Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.98 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];
inline bool compare(box a, box b)
{
    return a.z < b.z;
}
inline bool verif(box a, box b)
{
    return (a.x < b.x && a.y < b.y && a.z < b.z);
}
class InParser {
private:
	FILE *fin;
	char *buff;
	int sp;

	char read_ch() {
		++sp;
		if (sp == 4096) {
			sp = 0;
			fread(buff, 1, 4096, fin);
		}
		return buff[sp];
	}

public:
	InParser(const char* nume) {
		fin = fopen(nume, "r");
		buff = new char[4096]();
		sp = 4095;
	}

	InParser& operator >> (int &n) {
		char c;
		while (!isdigit(c = read_ch()) && c != '-');
		int sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}

	InParser& operator >> (long long &n) {
		char c;
		n = 0;
		while (!isdigit(c = read_ch()) && c != '-');
		long long sgn = 1;
		if (c == '-') {
			n = 0;
			sgn = -1;
		} else {
			n = c - '0';
		}
		while (isdigit(c = read_ch())) {
			n = 10 * n + c - '0';
		}
		n *= sgn;
		return *this;
	}
};
InParser 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;
}