이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1500025;
int n, a[MAXN], b[MAXN], c[MAXN];
vector <int> ind[3];
bool ok[MAXN];
int main () {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i] >> c[i];
ok[i] = 1;
for (int j = 0; j < 3; j++) ind[j].push_back(i);
}
sort(ind[0].begin(), ind[0].end(), [&] (int x, int y) {
return a[x] < a[y];
});
sort(ind[1].begin(), ind[1].end(), [&] (int x, int y) {
return b[x] < b[y];
});
sort(ind[2].begin(), ind[2].end(), [&] (int x, int y) {
return c[x] < c[y];
});
while (!(ind[0].empty() || ind[1].empty() || ind[2].empty())) {
int x = ind[0].back(), y = ind[1].back(), z = ind[2].back();
if (a[x] == a[y] || a[x] == a[z]) ok[x] = 0;
if (b[y] == b[x] || b[y] == b[z]) ok[y] = 0;
if (c[z] == c[x] || c[z] == c[y]) ok[z] = 0;
if (ok[x] && ok[y] && ok[z]) {
cout << a[x] + b[y] + c[z] << '\n';
return 0;
}
while (!ind[0].empty() && !ok[ind[0].back()]) ind[0].pop_back();
while (!ind[1].empty() && !ok[ind[1].back()]) ind[1].pop_back();
while (!ind[2].empty() && !ok[ind[2].back()]) ind[2].pop_back();
}
cout << "-1\n";
}
# | 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... |