Cod sursa(job #2644322)

Utilizator SochuDarabaneanu Liviu Eugen Sochu Data 24 august 2020 11:50:36
Problema Cutii Scor 100
Compilator cpp-64 Status done
Runda prbd2 Marime 1.6 kb
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >
#define pq priority_queue
#define dbg(x) cerr << #x << ": " << x << '\n'

using namespace std;

const int N = 3505;
const int M = 1e9 + 7;
const ld PI = acos(-1);

int n , t;

struct fig
{
    int x , y , z;
}a[N];

bool inline cmp(fig a , fig b)
{
    return a.x < b.x;
}

vector < int > dp[N];

bool inline ok(int mid , int ind)
{
    for(auto i : dp[mid])
        if(a[ind].y > a[i].y && a[ind].z > a[i].z)
            return 1;

    return 0;
}

int bs(int ind)
{
    int l = 1 , r = n , mid = 0 , ans = 0;

    while(l <= r)
    {
        mid = (r - l) / 2 + l;

        if(ok(mid , ind))
            ans = mid , l = mid + 1;
        else r = mid - 1;
    }

    dp[ans + 1].pb(ind);
    return ans + 1;
}

void Test()
{

    int i , ans = 0;

    for(i = 1 ; i <= n ; i++)
        cin >> a[i].x >> a[i].y >> a[i].z , dp[i].clear();

    sort(a + 1 , a + n + 1 , cmp);

    for(i = 1 ; i <= n ; i++)
        ans = max(ans , bs(i));

    cout << ans << '\n';
}

signed main()
{
	#ifndef ONLINE_JUDGE
	freopen("cutii.in" , "r" , stdin) , freopen("cutii.out" , "w" , stdout);
	#endif

	ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

    cin >> n >> t;

    while(t--)
        Test();

    return 0;
}