#include <bits/stdc++.h>
#include <random>
#ifndef LOCAL
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
typedef long long ll;
typedef double dd;
typedef long double ld;
typedef unsigned int uii;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void solve();
mt19937_64 mt(1);
int32_t main() {
#ifdef LOCAL
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#else
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
//freopen("amusing.in", "r", stdin);
//freopen("amusing.out", "w", stdout);
#endif
cout << fixed << setprecision(30);
int tests = 1;
//cin >> tests;
while (tests--) {
solve();
}
}
void solve() {
int n;
cin >> n;
set<pair<int, int>> xs, ys, zs;
vector<int> x(n), y(n), z(n);
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> z[i];
xs.emplace(-x[i], i);
ys.emplace(-y[i], i);
zs.emplace(-z[i], i);
}
while (!xs.empty()) {
pair<int, int> f = *xs.begin(), s = *ys.begin(), t = *zs.begin();
int i = f.y, j = s.y, l = t.y;
if (y[i] >= y[j] || z[i] >= z[l]) {
xs.erase({-x[i], i});
ys.erase({-y[i], i});
zs.erase({-z[i], i});
continue;
}
if (x[j] >= x[i] || z[j] >= z[l]) {
xs.erase({-x[j], j});
ys.erase({-y[j], j});
zs.erase({-z[j], j});
continue;
}
if (y[l] >= y[j] || x[l] >= x[i]) {
xs.erase({-x[l], l});
ys.erase({-y[l], l});
zs.erase({-z[l], l});
continue;
}
cout << -(f.x + t.x + s.x) << '\n';
return;
}
cout << "-1\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
3 ms |
1112 KB |
Output is correct |
28 |
Correct |
4 ms |
1112 KB |
Output is correct |
29 |
Correct |
4 ms |
1368 KB |
Output is correct |
30 |
Correct |
2 ms |
856 KB |
Output is correct |
31 |
Correct |
3 ms |
1112 KB |
Output is correct |
32 |
Correct |
4 ms |
1112 KB |
Output is correct |
33 |
Correct |
4 ms |
1112 KB |
Output is correct |
34 |
Correct |
3 ms |
1116 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
3 ms |
1112 KB |
Output is correct |
38 |
Correct |
3 ms |
1112 KB |
Output is correct |
39 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
118 ms |
23120 KB |
Output is correct |
12 |
Correct |
92 ms |
15592 KB |
Output is correct |
13 |
Correct |
90 ms |
19196 KB |
Output is correct |
14 |
Correct |
157 ms |
23116 KB |
Output is correct |
15 |
Correct |
125 ms |
23344 KB |
Output is correct |
16 |
Correct |
111 ms |
23236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
118 ms |
23120 KB |
Output is correct |
12 |
Correct |
92 ms |
15592 KB |
Output is correct |
13 |
Correct |
90 ms |
19196 KB |
Output is correct |
14 |
Correct |
157 ms |
23116 KB |
Output is correct |
15 |
Correct |
125 ms |
23344 KB |
Output is correct |
16 |
Correct |
111 ms |
23236 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
146 ms |
24400 KB |
Output is correct |
23 |
Correct |
149 ms |
23632 KB |
Output is correct |
24 |
Correct |
114 ms |
17744 KB |
Output is correct |
25 |
Correct |
219 ms |
24316 KB |
Output is correct |
26 |
Correct |
148 ms |
24144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
118 ms |
23120 KB |
Output is correct |
12 |
Correct |
92 ms |
15592 KB |
Output is correct |
13 |
Correct |
90 ms |
19196 KB |
Output is correct |
14 |
Correct |
157 ms |
23116 KB |
Output is correct |
15 |
Correct |
125 ms |
23344 KB |
Output is correct |
16 |
Correct |
111 ms |
23236 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
146 ms |
24400 KB |
Output is correct |
23 |
Correct |
149 ms |
23632 KB |
Output is correct |
24 |
Correct |
114 ms |
17744 KB |
Output is correct |
25 |
Correct |
219 ms |
24316 KB |
Output is correct |
26 |
Correct |
148 ms |
24144 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
4 ms |
1112 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
212 ms |
23712 KB |
Output is correct |
35 |
Correct |
210 ms |
22352 KB |
Output is correct |
36 |
Correct |
257 ms |
24660 KB |
Output is correct |
37 |
Correct |
266 ms |
24660 KB |
Output is correct |
38 |
Correct |
165 ms |
24152 KB |
Output is correct |
39 |
Correct |
70 ms |
15188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
118 ms |
23120 KB |
Output is correct |
12 |
Correct |
92 ms |
15592 KB |
Output is correct |
13 |
Correct |
90 ms |
19196 KB |
Output is correct |
14 |
Correct |
157 ms |
23116 KB |
Output is correct |
15 |
Correct |
125 ms |
23344 KB |
Output is correct |
16 |
Correct |
111 ms |
23236 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
146 ms |
24400 KB |
Output is correct |
23 |
Correct |
149 ms |
23632 KB |
Output is correct |
24 |
Correct |
114 ms |
17744 KB |
Output is correct |
25 |
Correct |
219 ms |
24316 KB |
Output is correct |
26 |
Correct |
148 ms |
24144 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
4 ms |
1112 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
212 ms |
23712 KB |
Output is correct |
35 |
Correct |
210 ms |
22352 KB |
Output is correct |
36 |
Correct |
257 ms |
24660 KB |
Output is correct |
37 |
Correct |
266 ms |
24660 KB |
Output is correct |
38 |
Correct |
165 ms |
24152 KB |
Output is correct |
39 |
Correct |
70 ms |
15188 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
3 ms |
1112 KB |
Output is correct |
42 |
Correct |
3 ms |
1112 KB |
Output is correct |
43 |
Correct |
3 ms |
1112 KB |
Output is correct |
44 |
Correct |
212 ms |
25176 KB |
Output is correct |
45 |
Correct |
303 ms |
25420 KB |
Output is correct |
46 |
Correct |
254 ms |
25168 KB |
Output is correct |
47 |
Correct |
303 ms |
25252 KB |
Output is correct |
48 |
Correct |
184 ms |
25368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
3 ms |
1112 KB |
Output is correct |
28 |
Correct |
4 ms |
1112 KB |
Output is correct |
29 |
Correct |
4 ms |
1368 KB |
Output is correct |
30 |
Correct |
2 ms |
856 KB |
Output is correct |
31 |
Correct |
3 ms |
1112 KB |
Output is correct |
32 |
Correct |
4 ms |
1112 KB |
Output is correct |
33 |
Correct |
4 ms |
1112 KB |
Output is correct |
34 |
Correct |
3 ms |
1116 KB |
Output is correct |
35 |
Correct |
1 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
3 ms |
1112 KB |
Output is correct |
38 |
Correct |
3 ms |
1112 KB |
Output is correct |
39 |
Correct |
2 ms |
600 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
0 ms |
344 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
1 ms |
344 KB |
Output is correct |
50 |
Correct |
118 ms |
23120 KB |
Output is correct |
51 |
Correct |
92 ms |
15592 KB |
Output is correct |
52 |
Correct |
90 ms |
19196 KB |
Output is correct |
53 |
Correct |
157 ms |
23116 KB |
Output is correct |
54 |
Correct |
125 ms |
23344 KB |
Output is correct |
55 |
Correct |
111 ms |
23236 KB |
Output is correct |
56 |
Correct |
0 ms |
344 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
2 ms |
600 KB |
Output is correct |
61 |
Correct |
146 ms |
24400 KB |
Output is correct |
62 |
Correct |
149 ms |
23632 KB |
Output is correct |
63 |
Correct |
114 ms |
17744 KB |
Output is correct |
64 |
Correct |
219 ms |
24316 KB |
Output is correct |
65 |
Correct |
148 ms |
24144 KB |
Output is correct |
66 |
Correct |
1 ms |
344 KB |
Output is correct |
67 |
Correct |
1 ms |
344 KB |
Output is correct |
68 |
Correct |
1 ms |
344 KB |
Output is correct |
69 |
Correct |
1 ms |
344 KB |
Output is correct |
70 |
Correct |
4 ms |
1112 KB |
Output is correct |
71 |
Correct |
1 ms |
600 KB |
Output is correct |
72 |
Correct |
1 ms |
604 KB |
Output is correct |
73 |
Correct |
212 ms |
23712 KB |
Output is correct |
74 |
Correct |
210 ms |
22352 KB |
Output is correct |
75 |
Correct |
257 ms |
24660 KB |
Output is correct |
76 |
Correct |
266 ms |
24660 KB |
Output is correct |
77 |
Correct |
165 ms |
24152 KB |
Output is correct |
78 |
Correct |
70 ms |
15188 KB |
Output is correct |
79 |
Correct |
2 ms |
856 KB |
Output is correct |
80 |
Correct |
3 ms |
1112 KB |
Output is correct |
81 |
Correct |
3 ms |
1112 KB |
Output is correct |
82 |
Correct |
3 ms |
1112 KB |
Output is correct |
83 |
Correct |
212 ms |
25176 KB |
Output is correct |
84 |
Correct |
303 ms |
25420 KB |
Output is correct |
85 |
Correct |
254 ms |
25168 KB |
Output is correct |
86 |
Correct |
303 ms |
25252 KB |
Output is correct |
87 |
Correct |
184 ms |
25368 KB |
Output is correct |
88 |
Correct |
257 ms |
27236 KB |
Output is correct |
89 |
Correct |
280 ms |
27072 KB |
Output is correct |
90 |
Correct |
228 ms |
27216 KB |
Output is correct |
91 |
Correct |
280 ms |
27216 KB |
Output is correct |
92 |
Correct |
261 ms |
25936 KB |
Output is correct |
93 |
Correct |
287 ms |
25936 KB |
Output is correct |
94 |
Correct |
334 ms |
26200 KB |
Output is correct |
95 |
Correct |
200 ms |
26960 KB |
Output is correct |
96 |
Correct |
188 ms |
27248 KB |
Output is correct |
97 |
Correct |
145 ms |
27220 KB |
Output is correct |
98 |
Correct |
94 ms |
25680 KB |
Output is correct |
99 |
Correct |
114 ms |
25680 KB |
Output is correct |