제출 #661087

#제출 시각아이디문제언어결과실행 시간메모리
661087Alex_tz307Team Contest (JOI22_team)C++17
100 / 100
124 ms10020 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n), b(n), c(n); priority_queue<pair<int, int>> X, Y, Z; for (int i = 0; i < n; ++i) { int x, y, z; cin >> x >> y >> z; a[i] = x, b[i] = y, c[i] = z; X.emplace(x, i), Y.emplace(y, i), Z.emplace(z, i); } int sol = -1; vector<bool> bad(n); while (!X.empty() && !Y.empty() && !Z.empty() && sol == -1) { while (!X.empty() && bad[X.top().second]) { X.pop(); } while (!Y.empty() && bad[Y.top().second]) { Y.pop(); } while (!Z.empty() && bad[Z.top().second]) { Z.pop(); } if (!X.empty() && !Y.empty() && !Z.empty()) { int x = X.top().second, y = Y.top().second, z = Z.top().second; if (b[x] == b[y] || c[x] == c[z]) { bad[x] = true; X.pop(); } else if (a[y] == a[x] || c[y] == c[z]) { bad[y] = true; Y.pop(); } else if (a[z] == a[x] || b[z] == b[y]) { bad[z] = true; Z.pop(); } else { sol = a[x] + b[y] + c[z]; } } } cout << sol << '\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...