Submission #635826

#TimeUsernameProblemLanguageResultExecution timeMemory
635826MahdiTeam Contest (JOI22_team)C++17
100 / 100
235 ms10244 KiB
#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 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...