#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
int N, ans, X[150005], Y[150005], Z[150005];
bool invalid[150005];
priority_queue<ii> pqX, pqY, pqZ;
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++){
cin >> X[i] >> Y[i] >> Z[i];
pqX.emplace(X[i], i);
pqY.emplace(Y[i], i);
pqZ.emplace(Z[i], i);
}
while (1) {
while (!pqX.empty() && invalid[pqX.top().second]) pqX.pop();
while (!pqY.empty() && invalid[pqY.top().second]) pqY.pop();
while (!pqZ.empty() && invalid[pqZ.top().second]) pqZ.pop();
if (pqX.empty() || pqY.empty() || pqZ.empty()) {
ans = -1;
break;
}
auto x = pqX.top(), y = pqY.top(), z = pqZ.top();
bool bad = 0;
for (auto i : {x.second, y.second, z.second}) {
int cnt = 0;
if (X[i] == x.first) cnt++;
if (Y[i] == y.first) cnt++;
if (Z[i] == z.first) cnt++;
assert(cnt > 0);
if (cnt > 1) {
invalid[i] = 1;
bad = 1;
}
}
if (!bad) {
ans = x.first + y.first + z.first;
break;
}
}
cout << ans << '\n';
}
Compilation message
team.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
496 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
496 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
4 ms |
764 KB |
Output is correct |
28 |
Correct |
2 ms |
736 KB |
Output is correct |
29 |
Correct |
4 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
3 ms |
724 KB |
Output is correct |
33 |
Correct |
3 ms |
724 KB |
Output is correct |
34 |
Correct |
4 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
2 ms |
732 KB |
Output is correct |
38 |
Correct |
2 ms |
724 KB |
Output is correct |
39 |
Correct |
1 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
41 ms |
12600 KB |
Output is correct |
12 |
Correct |
44 ms |
8124 KB |
Output is correct |
13 |
Correct |
33 ms |
10024 KB |
Output is correct |
14 |
Correct |
89 ms |
12600 KB |
Output is correct |
15 |
Correct |
93 ms |
12648 KB |
Output is correct |
16 |
Correct |
66 ms |
12656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
41 ms |
12600 KB |
Output is correct |
12 |
Correct |
44 ms |
8124 KB |
Output is correct |
13 |
Correct |
33 ms |
10024 KB |
Output is correct |
14 |
Correct |
89 ms |
12600 KB |
Output is correct |
15 |
Correct |
93 ms |
12648 KB |
Output is correct |
16 |
Correct |
66 ms |
12656 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
41 ms |
12840 KB |
Output is correct |
23 |
Correct |
52 ms |
12608 KB |
Output is correct |
24 |
Correct |
61 ms |
9000 KB |
Output is correct |
25 |
Correct |
104 ms |
12932 KB |
Output is correct |
26 |
Correct |
82 ms |
12712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
41 ms |
12600 KB |
Output is correct |
12 |
Correct |
44 ms |
8124 KB |
Output is correct |
13 |
Correct |
33 ms |
10024 KB |
Output is correct |
14 |
Correct |
89 ms |
12600 KB |
Output is correct |
15 |
Correct |
93 ms |
12648 KB |
Output is correct |
16 |
Correct |
66 ms |
12656 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
41 ms |
12840 KB |
Output is correct |
23 |
Correct |
52 ms |
12608 KB |
Output is correct |
24 |
Correct |
61 ms |
9000 KB |
Output is correct |
25 |
Correct |
104 ms |
12932 KB |
Output is correct |
26 |
Correct |
82 ms |
12712 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
42 ms |
13320 KB |
Output is correct |
35 |
Correct |
66 ms |
13128 KB |
Output is correct |
36 |
Correct |
68 ms |
13244 KB |
Output is correct |
37 |
Correct |
115 ms |
13380 KB |
Output is correct |
38 |
Correct |
87 ms |
13396 KB |
Output is correct |
39 |
Correct |
53 ms |
7840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
41 ms |
12600 KB |
Output is correct |
12 |
Correct |
44 ms |
8124 KB |
Output is correct |
13 |
Correct |
33 ms |
10024 KB |
Output is correct |
14 |
Correct |
89 ms |
12600 KB |
Output is correct |
15 |
Correct |
93 ms |
12648 KB |
Output is correct |
16 |
Correct |
66 ms |
12656 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
41 ms |
12840 KB |
Output is correct |
23 |
Correct |
52 ms |
12608 KB |
Output is correct |
24 |
Correct |
61 ms |
9000 KB |
Output is correct |
25 |
Correct |
104 ms |
12932 KB |
Output is correct |
26 |
Correct |
82 ms |
12712 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
42 ms |
13320 KB |
Output is correct |
35 |
Correct |
66 ms |
13128 KB |
Output is correct |
36 |
Correct |
68 ms |
13244 KB |
Output is correct |
37 |
Correct |
115 ms |
13380 KB |
Output is correct |
38 |
Correct |
87 ms |
13396 KB |
Output is correct |
39 |
Correct |
53 ms |
7840 KB |
Output is correct |
40 |
Correct |
2 ms |
596 KB |
Output is correct |
41 |
Correct |
2 ms |
724 KB |
Output is correct |
42 |
Correct |
2 ms |
724 KB |
Output is correct |
43 |
Correct |
3 ms |
756 KB |
Output is correct |
44 |
Correct |
51 ms |
13924 KB |
Output is correct |
45 |
Correct |
112 ms |
13736 KB |
Output is correct |
46 |
Correct |
92 ms |
13804 KB |
Output is correct |
47 |
Correct |
132 ms |
13772 KB |
Output is correct |
48 |
Correct |
91 ms |
13688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
496 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
4 ms |
764 KB |
Output is correct |
28 |
Correct |
2 ms |
736 KB |
Output is correct |
29 |
Correct |
4 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
3 ms |
724 KB |
Output is correct |
33 |
Correct |
3 ms |
724 KB |
Output is correct |
34 |
Correct |
4 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
2 ms |
732 KB |
Output is correct |
38 |
Correct |
2 ms |
724 KB |
Output is correct |
39 |
Correct |
1 ms |
484 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
41 ms |
12600 KB |
Output is correct |
51 |
Correct |
44 ms |
8124 KB |
Output is correct |
52 |
Correct |
33 ms |
10024 KB |
Output is correct |
53 |
Correct |
89 ms |
12600 KB |
Output is correct |
54 |
Correct |
93 ms |
12648 KB |
Output is correct |
55 |
Correct |
66 ms |
12656 KB |
Output is correct |
56 |
Correct |
0 ms |
336 KB |
Output is correct |
57 |
Correct |
1 ms |
336 KB |
Output is correct |
58 |
Correct |
0 ms |
336 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
41 ms |
12840 KB |
Output is correct |
62 |
Correct |
52 ms |
12608 KB |
Output is correct |
63 |
Correct |
61 ms |
9000 KB |
Output is correct |
64 |
Correct |
104 ms |
12932 KB |
Output is correct |
65 |
Correct |
82 ms |
12712 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
0 ms |
340 KB |
Output is correct |
68 |
Correct |
0 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
3 ms |
724 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
42 ms |
13320 KB |
Output is correct |
74 |
Correct |
66 ms |
13128 KB |
Output is correct |
75 |
Correct |
68 ms |
13244 KB |
Output is correct |
76 |
Correct |
115 ms |
13380 KB |
Output is correct |
77 |
Correct |
87 ms |
13396 KB |
Output is correct |
78 |
Correct |
53 ms |
7840 KB |
Output is correct |
79 |
Correct |
2 ms |
596 KB |
Output is correct |
80 |
Correct |
2 ms |
724 KB |
Output is correct |
81 |
Correct |
2 ms |
724 KB |
Output is correct |
82 |
Correct |
3 ms |
756 KB |
Output is correct |
83 |
Correct |
51 ms |
13924 KB |
Output is correct |
84 |
Correct |
112 ms |
13736 KB |
Output is correct |
85 |
Correct |
92 ms |
13804 KB |
Output is correct |
86 |
Correct |
132 ms |
13772 KB |
Output is correct |
87 |
Correct |
91 ms |
13688 KB |
Output is correct |
88 |
Correct |
61 ms |
15336 KB |
Output is correct |
89 |
Correct |
99 ms |
15312 KB |
Output is correct |
90 |
Correct |
62 ms |
15284 KB |
Output is correct |
91 |
Correct |
140 ms |
15356 KB |
Output is correct |
92 |
Correct |
68 ms |
14012 KB |
Output is correct |
93 |
Correct |
107 ms |
14468 KB |
Output is correct |
94 |
Correct |
127 ms |
14152 KB |
Output is correct |
95 |
Correct |
102 ms |
15232 KB |
Output is correct |
96 |
Correct |
118 ms |
15336 KB |
Output is correct |
97 |
Correct |
85 ms |
15400 KB |
Output is correct |
98 |
Correct |
56 ms |
14144 KB |
Output is correct |
99 |
Correct |
86 ms |
14116 KB |
Output is correct |