Submission #696157

#TimeUsernameProblemLanguageResultExecution timeMemory
696157hpesojTeam Contest (JOI22_team)C++17
100 / 100
117 ms15664 KiB
#include <bits/stdc++.h> #define int long long #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()); /*int randnums[200005]; void gen(){ for(int i = 0; i < 200005; i++){ randnums[i] = rng() / 200005 + 1; //cout << randnums[i] << '\n'; } }*/ signed main(){ ios::sync_with_stdio(0), cin.tie(0); memset(removed, 0, sizeof(removed)); 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(); if(x.empty() or y.empty() or z.empty()){ cout << -1; break; } int i = -1, j = -1, k = -1; if(!x.empty()){ i = x.back().se; //cout << x.back().fi << ' ' << i << ' '; } if(!y.empty()){ j = y.back().se; //cout << y.back().fi << ' ' << j << ' '; } if(!z.empty()){ k = z.back().se; //cout << z.back().fi << ' ' << k << ' '; } //cout << '\n'; if(i == j and j == k and i != -1) x.pop_back(), y.pop_back(), z.pop_back(), removed[i] = 1; else if(i == j and i != -1) x.pop_back(), y.pop_back(), removed[i] = 1; else if(i == k and i != -1) x.pop_back(), z.pop_back(), removed[i] = 1; else if(j == k and j != -1) 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; //cout << '\n' << i << ' ' << j << ' ' << k; 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...