This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> x(n), y(n), z(n);
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i] >> z[i];
}
vector<int> ptx(n), pty(n), ptz(n);
iota(ptx.begin(), ptx.end(), 0);
iota(pty.begin(), pty.end(), 0);
iota(ptz.begin(), ptz.end(), 0);
sort(ptx.begin(), ptx.end(), [&](int i, int j) {
return x[i] < x[j];
});
sort(pty.begin(), pty.end(), [&](int i, int j) {
return y[i] < y[j];
});
sort(ptz.begin(), ptz.end(), [&](int i, int j) {
return z[i] < z[j];
});
int tx = n - 1, ty = n - 1, tz = n - 1;
vector<bool> used(n);
while (tx >= 0 && ty >= 0 && tz >= 0) {
int mx = x[ptx[tx]], my = y[pty[ty]], mz = z[ptz[tz]];
int cntx = 1 + (y[ptx[tx]] == my) + (z[ptx[tx]] == mz);
int cnty = 1 + (x[pty[ty]] == mx) + (z[pty[ty]] == mz);
int cntz = 1 + (x[ptz[tz]] == mx) + (y[ptz[tz]] == mz);
if (cntx >= 2) {
used[ptx[tx]] = true;
tx--;
} else if (cnty >= 2) {
used[pty[ty]] = true;
ty--;
} else if (cntz >= 2) {
used[ptz[tz]] = true;
tz--;
} else {
cout << (long long) mx + my + mz << '\n';
return 0;
}
while (tx >= 0 && used[ptx[tx]]) tx--;
while (ty >= 0 && used[pty[ty]]) ty--;
while (tz >= 0 && used[ptz[tz]]) tz--;
}
cout << -1 << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |