This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |