Submission #1090604

#TimeUsernameProblemLanguageResultExecution timeMemory
1090604Neco_arcTeam Contest (JOI22_team)C++17
100 / 100
82 ms8528 KiB
#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL

#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Team Contest"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7

using namespace std;

const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;

int n;
int X[maxn], Y[maxn], Z[maxn];
int px[maxn], py[maxn], pz[maxn], del[maxn];

void solve()
{

    cin >> n;
    fi(i, 1, n) {
        cin >> X[i] >> Y[i] >> Z[i];
        px[i] = py[i] = pz[i] = i;
    }

    sort(px + 1, px + 1 + n, [](int i, int j) { return X[i] < X[j]; });
    sort(py + 1, py + 1 + n, [](int i, int j) { return Y[i] < Y[j]; });
    sort(pz + 1, pz + 1 + n, [](int i, int j) { return Z[i] < Z[j]; });

    int tx = n, ty = n, tz = n;

    while(tx && ty && tz) {
        int idx = px[tx], idy = py[ty], idz = pz[tz];
        if(del[idx]) { --tx; continue; }
        if(del[idy]) { --ty; continue; }
        if(del[idz]) { --tz; continue; }

        if(Y[idx] == Y[idy] || Z[idx] == Z[idz]) { del[idx] = 1; continue; }
        if(X[idy] == X[idx] || Z[idy] == Z[idz]) { del[idy] = 1; continue; }
        if(X[idz] == X[idx] || Y[idz] == Y[idy]) { del[idz] = 1; continue; }

        cout << 1ll * X[idx] + Y[idy] + Z[idz] << '\n';
        return;
    }

    cout << -1;

}


int main()
{

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

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;


    while(nTest--)
    {
        solve();
    }


    return 0;
}

Compilation message (stderr)

team.cpp: In function 'int main()':
team.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...