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>
#pragma GCC optimize ("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=15e4+5;
int n, x[N], y[N], z[N];
bool mk[N];
int main(){
cin>>n;
for(int i=0;i<n;++i)
cin>>x[i]>>y[i]>>z[i];
priority_queue<pii>a, b, c;
for(int i=0;i<n;++i){
a.push({x[i], i});
b.push({y[i], i});
c.push({z[i], i});
}
memset(mk, 1, sizeof(mk));
while(!a.empty()){
while(!a.empty() && !mk[a.top().S])
a.pop();
while(!b.empty() && !mk[b.top().S])
b.pop();
while(!c.empty() && !mk[c.top().S])
c.pop();
if(a.empty())
break;
int i=a.top().S, j=b.top().S, k=c.top().S;
if(y[i]==y[j] || z[i]==z[k]){
mk[i]=0;
a.pop();
continue;
}
if(x[j]==x[i] || z[j]==z[k]){
mk[j]=0;
b.pop();
continue;
}
if(x[k]==x[i] || y[k]==y[j]){
mk[k]=0;
c.pop();
continue;
}
cout<<x[i]+y[j]+z[k]<<'\n';
return 0;
}
cout<<-1<<'\n';
}
# | 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... |