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 debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const ll NMAX = 150005;
const ll INF = 1e9;
const ll nrbits = 20;
const ll MOD = 998244353;
set <int> x[NMAX];
vector <int> nx;
set <int> y[NMAX];
vector <int> ny;
set <int> z[NMAX];
vector <int> nz;
int xx[NMAX], yy[NMAX], zz[NMAX];
void nrm(vector <int> &x) {
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
}
int f[NMAX];
void sterge(set <int> &s, int x){
if(s.find(x) != s.end())
s.erase(x);
}
void totalDelete(int acum) {
sterge(x[xx[acum]], acum);
sterge(y[yy[acum]], acum);
sterge(z[zz[acum]], acum);
}
signed main() {
#ifdef HOME
ifstream cin(".in");
ofstream cout(".out");
#endif // HOME
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int i, n;
cin >> n;
for(i = 1; i <= n; i++) {
cin >> xx[i] >> yy[i] >> zz[i];
nx.push_back(xx[i]);
ny.push_back(yy[i]);
nz.push_back(zz[i]);
}
nrm(nx);
nrm(ny);
nrm(nz);
for(i = 1; i <= n; i++) {
xx[i] = lower_bound(nx.begin(), nx.end(), xx[i]) - nx.begin() + 1;
yy[i] = lower_bound(ny.begin(), ny.end(), yy[i]) - ny.begin() + 1;
zz[i] = lower_bound(nz.begin(), nz.end(), zz[i]) - nz.begin() + 1;
x[xx[i]].insert(i);
y[yy[i]].insert(i);
z[zz[i]].insert(i);
}
int indx = nx.size(), indy = ny.size(), indz = nz.size();
vector <int> toDel;
for(auto acum : x[indx]) {
f[acum]++;
if(f[acum] > 1) {
toDel.push_back(acum);
}
}
for(auto acum : y[indy]) {
f[acum]++;
if(f[acum] > 1) {
toDel.push_back(acum);
}
}
for(auto acum : z[indz]) {
f[acum]++;
if(f[acum] > 1) {
toDel.push_back(acum);
}
}
for(auto acum : toDel) {
totalDelete(acum);
}
int oke = 1;
while(oke && indx > 0 && indy > 0 && indz > 0) {
oke = 0;
while(indx > 0 && x[indx].size() == 0) {
toDel.clear(); /// Normal ca da TLE
indx--;
oke = 1;
for(auto acum : x[indx]) {
f[acum]++;
if(f[acum] > 1) {
toDel.push_back(acum);
}
}
for(auto acum : toDel) {
totalDelete(acum);
}
}
while(indy > 0 && y[indy].size() == 0) {
toDel.clear(); /// Normal ca da TLE
indy--;
oke = 1;
for(auto acum : y[indy]) {
f[acum]++;
if(f[acum] > 1) {
toDel.push_back(acum);
}
}
for(auto acum : toDel) {
totalDelete(acum);
}
}
while(indz > 0 && z[indz].size() == 0) {
toDel.clear(); /// Normal ca da TLE
indz--;
oke = 1;
for(auto acum : z[indz]) {
f[acum]++;
if(f[acum] > 1) {
toDel.push_back(acum);
}
}
for(auto acum : toDel) {
totalDelete(acum);
}
}
}
if(indx > 0 && indy > 0 && indz > 0) {
cout << nx[indx - 1] + ny[indy - 1] + nz[indz - 1];
} else {
cout << "-1";
}
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... |