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 <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct bober {
int x[3];
int num;
};
int n, indexSort=0, ix = 0, iy = 0, iz = 0;
bool tab[150010];
bober tx[150010], ty[150010], tz[150010];
bool sortuj(bober& a, bober& b) {
return a.x[indexSort] > b.x[indexSort];
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tx[i].x[0] >> tx[i].x[1] >> tx[i].x[2];
tx[i].num = i;
ty[i] = tx[i];
tz[i] = tx[i];
}
sort(tx, tx + n, sortuj);
indexSort++;
sort(ty, ty + n, sortuj);
indexSort++;
sort(tz, tz + n, sortuj);
while (ix < n && iy < n && iz < n) {
int maxx = tx[ix].x[0];
int maxy = ty[iy].x[1];
int maxz = tz[iz].x[2];
//cout << tx[ix].num << ' ' << ty[iy].num << ' ' << tz[iz].num << " : " << maxx << ' ' << maxy << ' ' << maxz << '\n';
if (tx[ix].x[1]==maxy||tx[ix].x[2]==maxz) {
tab[tx[ix].num] = true;
ix++;
}
else if (ty[iy].x[0] == maxx || ty[iy].x[2] == maxz) {
tab[ty[iy].num] = true;
iy++;
}
else if (tz[iz].x[1] == maxy || tz[iz].x[0] == maxx) {
tab[tz[iz].num] = true;
iz++;
}
else {
cout << maxx + maxy + maxz << '\n';
return 0;
}
while (ix < n && tab[tx[ix].num] == true) ix++;
while (iy < n && tab[ty[iy].num] == true) iy++;
while (iz < n && tab[tz[iz].num] == true) iz++;
}
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... |