# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
768400 | nguyentunglam | Team Contest (JOI22_team) | C++17 | 481 ms | 62876 KiB |
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>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 2e5 + 10;
int x[N], y[N], z[N];
map<pair<int, int>, vector<int> > m[3];
bool ban[N];
int X, Y, Z;
vector<ii> vx, vy, vz;
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int n; cin >> n;
for(int i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> z[i];
vx.emplace_back(x[i], i);
vy.emplace_back(y[i], i);
vz.emplace_back(z[i], i);
m[0][{x[i], y[i]}].push_back(i);
m[1][{y[i], z[i]}].push_back(i);
m[2][{x[i], z[i]}].push_back(i);
}
sort(vx.begin(), vx.end());
sort(vy.begin(), vy.end());
sort(vz.begin(), vz.end());
int cur = n;
while (cur >= 3) {
while (ban[vx.back().se]) vx.pop_back();
while (ban[vy.back().se]) vy.pop_back();
while (ban[vz.back().se]) vz.pop_back();
if (vx.empty() || vy.empty() || vz.empty()) break;
X = vx.back().first;
Y = vy.back().first;
Z = vz.back().first;
int pre = cur;
for(int &j : m[0][{X, Y}]) if (ban[j] == 0) {
cur--; ban[j] = 1;
}
for(int &j : m[1][{Y, Z}]) if (ban[j] == 0) {
cur--; ban[j] = 1;
}
for(int &j : m[2][{X, Z}]) if (ban[j] == 0) {
cur--; ban[j] = 1;
}
m[0][{X, Y}].clear();
m[1][{Y, Z}].clear();
m[2][{X, Z}].clear();
if (pre == cur) return cout << X + Y + Z, 0;
}
cout << -1;
}
Compilation message (stderr)
# | 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... |