Submission #938442

#TimeUsernameProblemLanguageResultExecution timeMemory
938442RegulusTeam Contest (JOI22_team)C++17
100 / 100
109 ms19908 KiB
#define TEST #include <bits/stdc++.h> #define IO ios::sync_with_stdio(false);cin.tie(0); #ifdef TEST #define debug(x) cerr << #x << " = " << (x) << ' ' #define bug(x) cerr << (x) << ' ' #define endl cerr << '\n' #else #define debug(x) cout << "" #define bug(x) cout << "" #define endl cout << "" #endif #define all(v) (v).begin(), (v).end() #define SZ(v) (ll)(v).size() #define lowbit(x) (x)&-(x) #define pb emplace_back #define F first #define S second using namespace std; using ll = long long; using pll = pair<ll, ll>; const int N = 2e5+5; int x[N], y[N], z[N]; bool del[N]; priority_queue<pll> pq, pq2, pq3; int main(void) { IO int n, i; cin >> n; for (i=1; i <= n; ++i) { cin >> x[i] >> y[i] >> z[i]; pq.push({x[i], i}); pq2.push({y[i], i}); pq3.push({z[i], i}); } while (!pq.empty() && !pq2.empty() && !pq3.empty()) { while (!pq.empty() && del[pq.top().S]) pq.pop(); while (!pq2.empty() && del[pq2.top().S]) pq2.pop(); while (!pq3.empty() && del[pq3.top().S]) pq3.pop(); if (pq.empty() || pq2.empty() || pq3.empty()) break; int a = pq.top().S, b = pq2.top().S, c = pq3.top().S; if (y[a] == y[b] || z[a] == z[c]) del[a] = 1; if (x[b] == x[a] || z[b] == z[c]) del[b] = 1; if (x[c] == x[a] || y[c] == y[b]) del[c] = 1; if (!del[a] && !del[b] && !del[c]) { cout << x[a] + y[b] + z[c] << '\n'; exit(0); } } cout << "-1\n"; return 0; }
#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...