#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) {
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) {
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) {
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 |
1 |
Correct |
6 ms |
23648 KB |
Output is correct |
2 |
Correct |
5 ms |
23644 KB |
Output is correct |
3 |
Correct |
5 ms |
23652 KB |
Output is correct |
4 |
Correct |
5 ms |
23652 KB |
Output is correct |
5 |
Correct |
5 ms |
23652 KB |
Output is correct |
6 |
Correct |
5 ms |
23656 KB |
Output is correct |
7 |
Correct |
5 ms |
23656 KB |
Output is correct |
8 |
Correct |
6 ms |
23656 KB |
Output is correct |
9 |
Correct |
5 ms |
23648 KB |
Output is correct |
10 |
Correct |
6 ms |
23736 KB |
Output is correct |
11 |
Correct |
5 ms |
23648 KB |
Output is correct |
12 |
Correct |
6 ms |
23644 KB |
Output is correct |
13 |
Correct |
6 ms |
23640 KB |
Output is correct |
14 |
Correct |
6 ms |
23656 KB |
Output is correct |
15 |
Correct |
6 ms |
23652 KB |
Output is correct |
16 |
Correct |
5 ms |
23656 KB |
Output is correct |
17 |
Correct |
6 ms |
23656 KB |
Output is correct |
18 |
Correct |
6 ms |
23656 KB |
Output is correct |
19 |
Correct |
5 ms |
23752 KB |
Output is correct |
20 |
Correct |
6 ms |
23792 KB |
Output is correct |
21 |
Correct |
6 ms |
23652 KB |
Output is correct |
22 |
Correct |
6 ms |
23640 KB |
Output is correct |
23 |
Correct |
5 ms |
23716 KB |
Output is correct |
24 |
Correct |
5 ms |
23644 KB |
Output is correct |
25 |
Correct |
5 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
23648 KB |
Output is correct |
2 |
Correct |
5 ms |
23644 KB |
Output is correct |
3 |
Correct |
5 ms |
23652 KB |
Output is correct |
4 |
Correct |
5 ms |
23652 KB |
Output is correct |
5 |
Correct |
5 ms |
23652 KB |
Output is correct |
6 |
Correct |
5 ms |
23656 KB |
Output is correct |
7 |
Correct |
5 ms |
23656 KB |
Output is correct |
8 |
Correct |
6 ms |
23656 KB |
Output is correct |
9 |
Correct |
5 ms |
23648 KB |
Output is correct |
10 |
Correct |
6 ms |
23736 KB |
Output is correct |
11 |
Correct |
5 ms |
23648 KB |
Output is correct |
12 |
Correct |
6 ms |
23644 KB |
Output is correct |
13 |
Correct |
6 ms |
23640 KB |
Output is correct |
14 |
Correct |
6 ms |
23656 KB |
Output is correct |
15 |
Correct |
6 ms |
23652 KB |
Output is correct |
16 |
Correct |
5 ms |
23656 KB |
Output is correct |
17 |
Correct |
6 ms |
23656 KB |
Output is correct |
18 |
Correct |
6 ms |
23656 KB |
Output is correct |
19 |
Correct |
5 ms |
23752 KB |
Output is correct |
20 |
Correct |
6 ms |
23792 KB |
Output is correct |
21 |
Correct |
6 ms |
23652 KB |
Output is correct |
22 |
Correct |
6 ms |
23640 KB |
Output is correct |
23 |
Correct |
5 ms |
23716 KB |
Output is correct |
24 |
Correct |
5 ms |
23644 KB |
Output is correct |
25 |
Correct |
5 ms |
23892 KB |
Output is correct |
26 |
Correct |
9 ms |
24408 KB |
Output is correct |
27 |
Correct |
13 ms |
24412 KB |
Output is correct |
28 |
Correct |
30 ms |
24356 KB |
Output is correct |
29 |
Correct |
172 ms |
24692 KB |
Output is correct |
30 |
Correct |
31 ms |
24264 KB |
Output is correct |
31 |
Correct |
11 ms |
24408 KB |
Output is correct |
32 |
Correct |
47 ms |
24412 KB |
Output is correct |
33 |
Correct |
86 ms |
24412 KB |
Output is correct |
34 |
Correct |
147 ms |
24524 KB |
Output is correct |
35 |
Correct |
6 ms |
23896 KB |
Output is correct |
36 |
Correct |
8 ms |
23900 KB |
Output is correct |
37 |
Correct |
7 ms |
24412 KB |
Output is correct |
38 |
Correct |
53 ms |
24460 KB |
Output is correct |
39 |
Correct |
6 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23644 KB |
Output is correct |
2 |
Correct |
5 ms |
23644 KB |
Output is correct |
3 |
Correct |
6 ms |
23640 KB |
Output is correct |
4 |
Correct |
5 ms |
23644 KB |
Output is correct |
5 |
Correct |
5 ms |
23644 KB |
Output is correct |
6 |
Correct |
5 ms |
23644 KB |
Output is correct |
7 |
Correct |
5 ms |
23652 KB |
Output is correct |
8 |
Correct |
5 ms |
23648 KB |
Output is correct |
9 |
Correct |
5 ms |
23652 KB |
Output is correct |
10 |
Correct |
5 ms |
23656 KB |
Output is correct |
11 |
Correct |
167 ms |
47888 KB |
Output is correct |
12 |
Correct |
196 ms |
40352 KB |
Output is correct |
13 |
Correct |
121 ms |
43476 KB |
Output is correct |
14 |
Correct |
314 ms |
49044 KB |
Output is correct |
15 |
Correct |
178 ms |
49156 KB |
Output is correct |
16 |
Correct |
152 ms |
49792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23644 KB |
Output is correct |
2 |
Correct |
5 ms |
23644 KB |
Output is correct |
3 |
Correct |
6 ms |
23640 KB |
Output is correct |
4 |
Correct |
5 ms |
23644 KB |
Output is correct |
5 |
Correct |
5 ms |
23644 KB |
Output is correct |
6 |
Correct |
5 ms |
23644 KB |
Output is correct |
7 |
Correct |
5 ms |
23652 KB |
Output is correct |
8 |
Correct |
5 ms |
23648 KB |
Output is correct |
9 |
Correct |
5 ms |
23652 KB |
Output is correct |
10 |
Correct |
5 ms |
23656 KB |
Output is correct |
11 |
Correct |
167 ms |
47888 KB |
Output is correct |
12 |
Correct |
196 ms |
40352 KB |
Output is correct |
13 |
Correct |
121 ms |
43476 KB |
Output is correct |
14 |
Correct |
314 ms |
49044 KB |
Output is correct |
15 |
Correct |
178 ms |
49156 KB |
Output is correct |
16 |
Correct |
152 ms |
49792 KB |
Output is correct |
17 |
Correct |
6 ms |
23644 KB |
Output is correct |
18 |
Correct |
5 ms |
23644 KB |
Output is correct |
19 |
Correct |
5 ms |
23644 KB |
Output is correct |
20 |
Correct |
5 ms |
23644 KB |
Output is correct |
21 |
Correct |
7 ms |
24040 KB |
Output is correct |
22 |
Correct |
178 ms |
47804 KB |
Output is correct |
23 |
Correct |
325 ms |
47500 KB |
Output is correct |
24 |
Correct |
373 ms |
41996 KB |
Output is correct |
25 |
Correct |
766 ms |
49400 KB |
Output is correct |
26 |
Correct |
197 ms |
49212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23644 KB |
Output is correct |
2 |
Correct |
5 ms |
23644 KB |
Output is correct |
3 |
Correct |
6 ms |
23640 KB |
Output is correct |
4 |
Correct |
5 ms |
23644 KB |
Output is correct |
5 |
Correct |
5 ms |
23644 KB |
Output is correct |
6 |
Correct |
5 ms |
23644 KB |
Output is correct |
7 |
Correct |
5 ms |
23652 KB |
Output is correct |
8 |
Correct |
5 ms |
23648 KB |
Output is correct |
9 |
Correct |
5 ms |
23652 KB |
Output is correct |
10 |
Correct |
5 ms |
23656 KB |
Output is correct |
11 |
Correct |
167 ms |
47888 KB |
Output is correct |
12 |
Correct |
196 ms |
40352 KB |
Output is correct |
13 |
Correct |
121 ms |
43476 KB |
Output is correct |
14 |
Correct |
314 ms |
49044 KB |
Output is correct |
15 |
Correct |
178 ms |
49156 KB |
Output is correct |
16 |
Correct |
152 ms |
49792 KB |
Output is correct |
17 |
Correct |
6 ms |
23644 KB |
Output is correct |
18 |
Correct |
5 ms |
23644 KB |
Output is correct |
19 |
Correct |
5 ms |
23644 KB |
Output is correct |
20 |
Correct |
5 ms |
23644 KB |
Output is correct |
21 |
Correct |
7 ms |
24040 KB |
Output is correct |
22 |
Correct |
178 ms |
47804 KB |
Output is correct |
23 |
Correct |
325 ms |
47500 KB |
Output is correct |
24 |
Correct |
373 ms |
41996 KB |
Output is correct |
25 |
Correct |
766 ms |
49400 KB |
Output is correct |
26 |
Correct |
197 ms |
49212 KB |
Output is correct |
27 |
Correct |
5 ms |
23640 KB |
Output is correct |
28 |
Correct |
6 ms |
23640 KB |
Output is correct |
29 |
Correct |
5 ms |
23644 KB |
Output is correct |
30 |
Correct |
6 ms |
23644 KB |
Output is correct |
31 |
Correct |
39 ms |
24472 KB |
Output is correct |
32 |
Correct |
5 ms |
23900 KB |
Output is correct |
33 |
Correct |
9 ms |
23896 KB |
Output is correct |
34 |
Correct |
219 ms |
47280 KB |
Output is correct |
35 |
Execution timed out |
2043 ms |
46516 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23644 KB |
Output is correct |
2 |
Correct |
5 ms |
23644 KB |
Output is correct |
3 |
Correct |
6 ms |
23640 KB |
Output is correct |
4 |
Correct |
5 ms |
23644 KB |
Output is correct |
5 |
Correct |
5 ms |
23644 KB |
Output is correct |
6 |
Correct |
5 ms |
23644 KB |
Output is correct |
7 |
Correct |
5 ms |
23652 KB |
Output is correct |
8 |
Correct |
5 ms |
23648 KB |
Output is correct |
9 |
Correct |
5 ms |
23652 KB |
Output is correct |
10 |
Correct |
5 ms |
23656 KB |
Output is correct |
11 |
Correct |
167 ms |
47888 KB |
Output is correct |
12 |
Correct |
196 ms |
40352 KB |
Output is correct |
13 |
Correct |
121 ms |
43476 KB |
Output is correct |
14 |
Correct |
314 ms |
49044 KB |
Output is correct |
15 |
Correct |
178 ms |
49156 KB |
Output is correct |
16 |
Correct |
152 ms |
49792 KB |
Output is correct |
17 |
Correct |
6 ms |
23644 KB |
Output is correct |
18 |
Correct |
5 ms |
23644 KB |
Output is correct |
19 |
Correct |
5 ms |
23644 KB |
Output is correct |
20 |
Correct |
5 ms |
23644 KB |
Output is correct |
21 |
Correct |
7 ms |
24040 KB |
Output is correct |
22 |
Correct |
178 ms |
47804 KB |
Output is correct |
23 |
Correct |
325 ms |
47500 KB |
Output is correct |
24 |
Correct |
373 ms |
41996 KB |
Output is correct |
25 |
Correct |
766 ms |
49400 KB |
Output is correct |
26 |
Correct |
197 ms |
49212 KB |
Output is correct |
27 |
Correct |
5 ms |
23640 KB |
Output is correct |
28 |
Correct |
6 ms |
23640 KB |
Output is correct |
29 |
Correct |
5 ms |
23644 KB |
Output is correct |
30 |
Correct |
6 ms |
23644 KB |
Output is correct |
31 |
Correct |
39 ms |
24472 KB |
Output is correct |
32 |
Correct |
5 ms |
23900 KB |
Output is correct |
33 |
Correct |
9 ms |
23896 KB |
Output is correct |
34 |
Correct |
219 ms |
47280 KB |
Output is correct |
35 |
Execution timed out |
2043 ms |
46516 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
23648 KB |
Output is correct |
2 |
Correct |
5 ms |
23644 KB |
Output is correct |
3 |
Correct |
5 ms |
23652 KB |
Output is correct |
4 |
Correct |
5 ms |
23652 KB |
Output is correct |
5 |
Correct |
5 ms |
23652 KB |
Output is correct |
6 |
Correct |
5 ms |
23656 KB |
Output is correct |
7 |
Correct |
5 ms |
23656 KB |
Output is correct |
8 |
Correct |
6 ms |
23656 KB |
Output is correct |
9 |
Correct |
5 ms |
23648 KB |
Output is correct |
10 |
Correct |
6 ms |
23736 KB |
Output is correct |
11 |
Correct |
5 ms |
23648 KB |
Output is correct |
12 |
Correct |
6 ms |
23644 KB |
Output is correct |
13 |
Correct |
6 ms |
23640 KB |
Output is correct |
14 |
Correct |
6 ms |
23656 KB |
Output is correct |
15 |
Correct |
6 ms |
23652 KB |
Output is correct |
16 |
Correct |
5 ms |
23656 KB |
Output is correct |
17 |
Correct |
6 ms |
23656 KB |
Output is correct |
18 |
Correct |
6 ms |
23656 KB |
Output is correct |
19 |
Correct |
5 ms |
23752 KB |
Output is correct |
20 |
Correct |
6 ms |
23792 KB |
Output is correct |
21 |
Correct |
6 ms |
23652 KB |
Output is correct |
22 |
Correct |
6 ms |
23640 KB |
Output is correct |
23 |
Correct |
5 ms |
23716 KB |
Output is correct |
24 |
Correct |
5 ms |
23644 KB |
Output is correct |
25 |
Correct |
5 ms |
23892 KB |
Output is correct |
26 |
Correct |
9 ms |
24408 KB |
Output is correct |
27 |
Correct |
13 ms |
24412 KB |
Output is correct |
28 |
Correct |
30 ms |
24356 KB |
Output is correct |
29 |
Correct |
172 ms |
24692 KB |
Output is correct |
30 |
Correct |
31 ms |
24264 KB |
Output is correct |
31 |
Correct |
11 ms |
24408 KB |
Output is correct |
32 |
Correct |
47 ms |
24412 KB |
Output is correct |
33 |
Correct |
86 ms |
24412 KB |
Output is correct |
34 |
Correct |
147 ms |
24524 KB |
Output is correct |
35 |
Correct |
6 ms |
23896 KB |
Output is correct |
36 |
Correct |
8 ms |
23900 KB |
Output is correct |
37 |
Correct |
7 ms |
24412 KB |
Output is correct |
38 |
Correct |
53 ms |
24460 KB |
Output is correct |
39 |
Correct |
6 ms |
23900 KB |
Output is correct |
40 |
Correct |
5 ms |
23644 KB |
Output is correct |
41 |
Correct |
5 ms |
23644 KB |
Output is correct |
42 |
Correct |
6 ms |
23640 KB |
Output is correct |
43 |
Correct |
5 ms |
23644 KB |
Output is correct |
44 |
Correct |
5 ms |
23644 KB |
Output is correct |
45 |
Correct |
5 ms |
23644 KB |
Output is correct |
46 |
Correct |
5 ms |
23652 KB |
Output is correct |
47 |
Correct |
5 ms |
23648 KB |
Output is correct |
48 |
Correct |
5 ms |
23652 KB |
Output is correct |
49 |
Correct |
5 ms |
23656 KB |
Output is correct |
50 |
Correct |
167 ms |
47888 KB |
Output is correct |
51 |
Correct |
196 ms |
40352 KB |
Output is correct |
52 |
Correct |
121 ms |
43476 KB |
Output is correct |
53 |
Correct |
314 ms |
49044 KB |
Output is correct |
54 |
Correct |
178 ms |
49156 KB |
Output is correct |
55 |
Correct |
152 ms |
49792 KB |
Output is correct |
56 |
Correct |
6 ms |
23644 KB |
Output is correct |
57 |
Correct |
5 ms |
23644 KB |
Output is correct |
58 |
Correct |
5 ms |
23644 KB |
Output is correct |
59 |
Correct |
5 ms |
23644 KB |
Output is correct |
60 |
Correct |
7 ms |
24040 KB |
Output is correct |
61 |
Correct |
178 ms |
47804 KB |
Output is correct |
62 |
Correct |
325 ms |
47500 KB |
Output is correct |
63 |
Correct |
373 ms |
41996 KB |
Output is correct |
64 |
Correct |
766 ms |
49400 KB |
Output is correct |
65 |
Correct |
197 ms |
49212 KB |
Output is correct |
66 |
Correct |
5 ms |
23640 KB |
Output is correct |
67 |
Correct |
6 ms |
23640 KB |
Output is correct |
68 |
Correct |
5 ms |
23644 KB |
Output is correct |
69 |
Correct |
6 ms |
23644 KB |
Output is correct |
70 |
Correct |
39 ms |
24472 KB |
Output is correct |
71 |
Correct |
5 ms |
23900 KB |
Output is correct |
72 |
Correct |
9 ms |
23896 KB |
Output is correct |
73 |
Correct |
219 ms |
47280 KB |
Output is correct |
74 |
Execution timed out |
2043 ms |
46516 KB |
Time limit exceeded |
75 |
Halted |
0 ms |
0 KB |
- |