#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<array<int, 3>> a(n);
set<pair<int, int>, greater<>> mx[3];
for (int i = 0; i < n; ++i) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
mx[0].emplace(a[i][0], i);
mx[1].emplace(a[i][1], i);
mx[2].emplace(a[i][2], i);
}
while (mx[0].size() > 2) {
int i = mx[0].begin()->second;
int j = mx[1].begin()->second;
int k = mx[2].begin()->second;
array<int, 3> b{a[i][0], a[j][1], a[k][2]};
bool yay = true;
for (int x : {i, j, k}) {
int cnt = 0;
for (int p = 0; p < 3; ++p) {
cnt += a[x][p] == b[p];
}
if (cnt >= 2) {
yay = false;
mx[0].erase({a[x][0], x});
mx[1].erase({a[x][1], x});
mx[2].erase({a[x][2], x});
break;
}
}
if (yay) {
cout << b[0] + b[1] + b[2] << '\n';
return 0;
}
}
cout << "-1\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 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 |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
4 ms |
976 KB |
Output is correct |
29 |
Correct |
5 ms |
980 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
5 ms |
980 KB |
Output is correct |
32 |
Correct |
5 ms |
980 KB |
Output is correct |
33 |
Correct |
4 ms |
980 KB |
Output is correct |
34 |
Correct |
4 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
980 KB |
Output is correct |
38 |
Correct |
3 ms |
976 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
170 ms |
24060 KB |
Output is correct |
12 |
Correct |
140 ms |
16144 KB |
Output is correct |
13 |
Correct |
144 ms |
19808 KB |
Output is correct |
14 |
Correct |
211 ms |
24012 KB |
Output is correct |
15 |
Correct |
154 ms |
24048 KB |
Output is correct |
16 |
Correct |
172 ms |
24112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
170 ms |
24060 KB |
Output is correct |
12 |
Correct |
140 ms |
16144 KB |
Output is correct |
13 |
Correct |
144 ms |
19808 KB |
Output is correct |
14 |
Correct |
211 ms |
24012 KB |
Output is correct |
15 |
Correct |
154 ms |
24048 KB |
Output is correct |
16 |
Correct |
172 ms |
24112 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
328 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
588 KB |
Output is correct |
22 |
Correct |
199 ms |
24284 KB |
Output is correct |
23 |
Correct |
221 ms |
23528 KB |
Output is correct |
24 |
Correct |
178 ms |
17648 KB |
Output is correct |
25 |
Correct |
307 ms |
24228 KB |
Output is correct |
26 |
Correct |
178 ms |
24092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
170 ms |
24060 KB |
Output is correct |
12 |
Correct |
140 ms |
16144 KB |
Output is correct |
13 |
Correct |
144 ms |
19808 KB |
Output is correct |
14 |
Correct |
211 ms |
24012 KB |
Output is correct |
15 |
Correct |
154 ms |
24048 KB |
Output is correct |
16 |
Correct |
172 ms |
24112 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
328 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
588 KB |
Output is correct |
22 |
Correct |
199 ms |
24284 KB |
Output is correct |
23 |
Correct |
221 ms |
23528 KB |
Output is correct |
24 |
Correct |
178 ms |
17648 KB |
Output is correct |
25 |
Correct |
307 ms |
24228 KB |
Output is correct |
26 |
Correct |
178 ms |
24092 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
304 ms |
23632 KB |
Output is correct |
35 |
Correct |
277 ms |
22392 KB |
Output is correct |
36 |
Correct |
364 ms |
24720 KB |
Output is correct |
37 |
Correct |
385 ms |
24628 KB |
Output is correct |
38 |
Correct |
247 ms |
24220 KB |
Output is correct |
39 |
Correct |
95 ms |
14924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
170 ms |
24060 KB |
Output is correct |
12 |
Correct |
140 ms |
16144 KB |
Output is correct |
13 |
Correct |
144 ms |
19808 KB |
Output is correct |
14 |
Correct |
211 ms |
24012 KB |
Output is correct |
15 |
Correct |
154 ms |
24048 KB |
Output is correct |
16 |
Correct |
172 ms |
24112 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
328 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
588 KB |
Output is correct |
22 |
Correct |
199 ms |
24284 KB |
Output is correct |
23 |
Correct |
221 ms |
23528 KB |
Output is correct |
24 |
Correct |
178 ms |
17648 KB |
Output is correct |
25 |
Correct |
307 ms |
24228 KB |
Output is correct |
26 |
Correct |
178 ms |
24092 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
304 ms |
23632 KB |
Output is correct |
35 |
Correct |
277 ms |
22392 KB |
Output is correct |
36 |
Correct |
364 ms |
24720 KB |
Output is correct |
37 |
Correct |
385 ms |
24628 KB |
Output is correct |
38 |
Correct |
247 ms |
24220 KB |
Output is correct |
39 |
Correct |
95 ms |
14924 KB |
Output is correct |
40 |
Correct |
3 ms |
724 KB |
Output is correct |
41 |
Correct |
4 ms |
980 KB |
Output is correct |
42 |
Correct |
3 ms |
876 KB |
Output is correct |
43 |
Correct |
5 ms |
980 KB |
Output is correct |
44 |
Correct |
462 ms |
25276 KB |
Output is correct |
45 |
Correct |
522 ms |
25324 KB |
Output is correct |
46 |
Correct |
506 ms |
25208 KB |
Output is correct |
47 |
Correct |
522 ms |
25336 KB |
Output is correct |
48 |
Correct |
257 ms |
25116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 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 |
4 ms |
980 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
4 ms |
976 KB |
Output is correct |
29 |
Correct |
5 ms |
980 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
5 ms |
980 KB |
Output is correct |
32 |
Correct |
5 ms |
980 KB |
Output is correct |
33 |
Correct |
4 ms |
980 KB |
Output is correct |
34 |
Correct |
4 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
2 ms |
980 KB |
Output is correct |
38 |
Correct |
3 ms |
976 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
324 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
170 ms |
24060 KB |
Output is correct |
51 |
Correct |
140 ms |
16144 KB |
Output is correct |
52 |
Correct |
144 ms |
19808 KB |
Output is correct |
53 |
Correct |
211 ms |
24012 KB |
Output is correct |
54 |
Correct |
154 ms |
24048 KB |
Output is correct |
55 |
Correct |
172 ms |
24112 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
0 ms |
328 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
588 KB |
Output is correct |
61 |
Correct |
199 ms |
24284 KB |
Output is correct |
62 |
Correct |
221 ms |
23528 KB |
Output is correct |
63 |
Correct |
178 ms |
17648 KB |
Output is correct |
64 |
Correct |
307 ms |
24228 KB |
Output is correct |
65 |
Correct |
178 ms |
24092 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
320 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
5 ms |
980 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
2 ms |
468 KB |
Output is correct |
73 |
Correct |
304 ms |
23632 KB |
Output is correct |
74 |
Correct |
277 ms |
22392 KB |
Output is correct |
75 |
Correct |
364 ms |
24720 KB |
Output is correct |
76 |
Correct |
385 ms |
24628 KB |
Output is correct |
77 |
Correct |
247 ms |
24220 KB |
Output is correct |
78 |
Correct |
95 ms |
14924 KB |
Output is correct |
79 |
Correct |
3 ms |
724 KB |
Output is correct |
80 |
Correct |
4 ms |
980 KB |
Output is correct |
81 |
Correct |
3 ms |
876 KB |
Output is correct |
82 |
Correct |
5 ms |
980 KB |
Output is correct |
83 |
Correct |
462 ms |
25276 KB |
Output is correct |
84 |
Correct |
522 ms |
25324 KB |
Output is correct |
85 |
Correct |
506 ms |
25208 KB |
Output is correct |
86 |
Correct |
522 ms |
25336 KB |
Output is correct |
87 |
Correct |
257 ms |
25116 KB |
Output is correct |
88 |
Correct |
346 ms |
27008 KB |
Output is correct |
89 |
Correct |
415 ms |
27108 KB |
Output is correct |
90 |
Correct |
375 ms |
27048 KB |
Output is correct |
91 |
Correct |
447 ms |
27020 KB |
Output is correct |
92 |
Correct |
431 ms |
25620 KB |
Output is correct |
93 |
Correct |
401 ms |
25896 KB |
Output is correct |
94 |
Correct |
488 ms |
25816 KB |
Output is correct |
95 |
Correct |
253 ms |
26920 KB |
Output is correct |
96 |
Correct |
319 ms |
27040 KB |
Output is correct |
97 |
Correct |
181 ms |
27144 KB |
Output is correct |
98 |
Correct |
126 ms |
25740 KB |
Output is correct |
99 |
Correct |
172 ms |
25672 KB |
Output is correct |