Submission #586151

#TimeUsernameProblemLanguageResultExecution timeMemory
586151notaTeam Contest (JOI22_team)C++14
100 / 100
114 ms7936 KiB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
using namespace std;
const int maxN = 150001;
int n;
int x[maxN], y[maxN], z[maxN];

void Input()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> x[i] >> y[i] >> z[i];
}

int idx[maxN], idy[maxN], idz[maxN];
bool flag[maxN];

bool ss1(int a, int b)
{
    return x[a] < x[b];
}

bool ss2(int a, int b)
{
    return y[a] < y[b];
}

bool ss3(int a, int b)
{
    return z[a] < z[b];
}

void Solve()
{
    for(int i = 1; i <= n; i++)
    {
        idx[i] = i;
        idy[i] = i;
        idz[i] = i;
    }
    sort(idx + 1, idx + 1 + n, ss1);
    sort(idy + 1, idy + 1 + n, ss2);
    sort(idz + 1, idz + 1 + n, ss3);
    int resx = n, resy = n, resz = n;
    while(resx != 0 && resy != 0 && resz != 0)
    {
        int tmpx = x[idx[resx]], tmpy = y[idy[resy]], tmpz = z[idz[resz]];
        int xx = (y[idx[resx]] == tmpy) + (z[idx[resx]] == tmpz);
        int yy = (z[idy[resy]] == tmpz) + (x[idy[resy]] == tmpx);
        int zz = (x[idz[resz]] == tmpx) + (y[idz[resz]] == tmpy);
        if(xx == 0 && yy == 0 && zz == 0)
        {
            cout << tmpx + tmpy + tmpz;
            return;
        }
        if(xx > 0)
        {
            flag[idx[resx]] = true;
            goto hi;
        }
        if(yy > 0)
        {
            flag[idy[resy]] = true;
            goto hi;
        }
        if(zz > 0)
        {
            flag[idz[resz]] = true;
            goto hi;
        }
        hi:
        while(resx != 0 && flag[idx[resx]])
            resx--;
        while(resy != 0 && flag[idy[resy]])
            resy--;
        while(resz != 0 && flag[idz[resz]])
            resz--;
    }
    cout << -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Input();
    Solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...