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;
#define pb push_back
#define int long long
#define all(a) a.begin(),a.end()
const int mxN = (int)1.5e5+10;
struct Coder{ int x, y, z, i; };
vector<Coder> coder;
bool bad[mxN];
int n;
int32_t main() {
cin >> n;
for(int i = 0; i < n; i++){
int x,y,z; cin >>x>>y>>z;
coder.pb({x,y,z,i});
}
sort(all(coder),[&](Coder a, Coder b){
return a.x < b.x;
});
auto coderx = coder;
sort(all(coder),[&](Coder a, Coder b){
return a.y < b.y;
});
auto codery = coder;
sort(all(coder),[&](Coder a, Coder b){
return a.z < b.z;
});
auto coderz = coder;
int i = n-1, j = n-1, k = n-1;
while(1){
while(i>=0 and bad[coderx[i].i]) i--;
while(j>=0 and bad[codery[j].i]) j--;
while(k>=0 and bad[coderz[k].i]) k--;
if(i<0 or j<0 or k<0) {cout<<-1;return 0;}
int X = coderx[i].x, Y = codery[j].y, Z = coderz[k].z;
if(coderx[i].y==Y) bad[coderx[i].i]=1;
if(coderx[i].z==Z) bad[coderx[i].i]=1;
if(codery[j].x==X) bad[codery[j].i]=1;
if(codery[j].z==Z) bad[codery[j].i]=1;
if(coderz[k].x==X) bad[coderz[k].i]=1;
if(coderz[k].y==Y) bad[coderz[k].i]=1;
if(!bad[coderx[i].i] and !bad[codery[j].i] and !bad[coderz[k].i]){
cout << X+Y+Z; 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... |