Submission #696275

#TimeUsernameProblemLanguageResultExecution timeMemory
696275hpesojTeam Contest (JOI22_team)C++17
100 / 100
96 ms7860 KiB
#include <bits/stdc++.h> #define pi pair <int, int> #define ppi pair <pi, int> #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() using namespace std; int n, t, c, f, g, h, X[150005], Y[150005], Z[150005]; vector <pi> x, y, z; bool removed[150005]; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); signed main(){ ios::sync_with_stdio(0), cin.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> f >> g >> h; X[i] = f, Y[i] = g, Z[i] = h; x.pb({f, i}), y.pb({g, i}), z.pb({h, i}); } sort(all(x)), sort(all(y)), sort(all(z)); while(1){ while(!x.empty() and removed[x.back().se]) x.pop_back(); while(!y.empty() and removed[y.back().se]) y.pop_back(); while(!z.empty() and removed[z.back().se]) z.pop_back(); int i, j, k; if(x.empty() or y.empty() or z.empty()){ cout << -1; break; } else i = x.back().se, j = y.back().se, k = z.back().se; if(i == j and j == k) x.pop_back(), y.pop_back(), z.pop_back(), removed[i] = 1; else if(i == j) x.pop_back(), y.pop_back(), removed[i] = 1; else if(i == k) x.pop_back(), z.pop_back(), removed[i] = 1; else if(j == k) y.pop_back(), z.pop_back(), removed[j] = 1; else{ bool b = 0; if(Y[i] == y.back().fi or Z[i] == z.back().fi) b = 1, removed[i] = 1, x.pop_back(); if(X[j] == x.back().fi or Z[j] == z.back().fi) b = 1, removed[j] = 1, y.pop_back(); if(X[k] == x.back().fi or Y[k] == y.back().fi) b = 1, removed[k] = 1, z.pop_back(); if(b) continue; cout << x.back().fi + y.back().fi + z.back().fi; break; } } }
#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...