Submission #582742

#TimeUsernameProblemLanguageResultExecution timeMemory
582742elkernosTeam Contest (JOI22_team)C++17
100 / 100
116 ms7772 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(0); int n; cin >> n; vector<int> x(n + 1), y(n + 1), z(n + 1); for(int i = 1; i <= n; i++) { cin >> x[i] >> y[i] >> z[i]; } vector<int> px(n + 1), py(n + 1), pz(n + 1); for(int i = 1; i <= n; i++) { px[i] = i; py[i] = i; pz[i] = i; } sort(px.begin() + 1, px.end(), [&](int i, int j) { return x[i] < x[j]; }); sort(py.begin() + 1, py.end(), [&](int i, int j) { return y[i] < y[j]; }); sort(pz.begin() + 1, pz.end(), [&](int i, int j) { return z[i] < z[j]; }); vector<bool> used(n + 1); int tx = n, ty = n, tz = n; while(tx != 0 && ty != 0 && tz != 0) { int mx = x[px[tx]], my = y[py[ty]], mz = z[pz[tz]]; int cntx = 1 + (y[px[tx]] == my) + (z[px[tx]] == mz); int cnty = 1 + (z[py[ty]] == mz) + (x[py[ty]] == mx); int cntz = 1 + (x[pz[tz]] == mx) + (y[pz[tz]] == my); if(cntx >= 2) { used[px[tx]] = true; tx--; } else if(cnty >= 2) { used[py[ty]] = true; ty--; } else if(cntz >= 2) { used[pz[tz]] = true; tz--; } else { cout << mx + my + mz << '\n'; exit(0); } while(tx != 0 && used[px[tx]]) tx--; while(ty != 0 && used[py[ty]]) ty--; while(tz != 0 && used[pz[tz]]) tz--; } 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...