#include <bits//stdc++.h>
using namespace std;
#define ll long long
#define st short
#define iloop(m, h) for (auto i = m; i != h; i+=(m<h?1:-1))
#define jloop(m, h) for (auto j = m; j != h; j+=(m<h?1:-1))
#define kloop(m, h) for (auto k = m; k != h; k+=(m<h?1:-1))
#define lloop(m, h) for (auto l = m; l != h; l+=(m<h?1:-1))
#define iloop_(m, h, g) for (auto i = m; i != h; i+=g)
#define jloop_(m, h, g) for (auto j = m; j != h; j+=g)
#define kloop_(m, h, g) for (auto k = m; k != h; k+=g)
#define lloop_(m, h, g) for (auto l = m; l != h; l+=g)
#define getchar_unlocked _getchar_nolock // comment before submission
#define pll pair<ll,ll>
#define plll pair<ll, pll>
#define pllll pair<pll, pll>
#define vll vector<ll>
#define qll queue<ll>
#define dll deque<ll>
#define pqll priority_queue<ll>
#define gll greater<ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
ll ax[n], ay[n], az[n];
pll x[n], y[n], z[n];
bool there[n];
iloop(0, n) {
there[i] = 1;
cin >> ax[i] >> ay[i] >> az[i];
x[i].first = ax[i], y[i].first = ay[i], z[i].first = az[i];
x[i].second = y[i].second = z[i].second = i;
}
sort(x, x+n);
sort(y, y+n);
sort(z, z+n);
ll cnt1 = n-1, cnt2 = n-1, cnt3 = n-1;
while (cnt1 >= 0) {
while (cnt1 >= 0 && there[x[cnt1].second] == 0) cnt1--;
while (cnt2 >= 0 && there[y[cnt2].second] == 0) cnt2--;
while (cnt3 >= 0 && there[z[cnt3].second] == 0) cnt3--;
if (cnt1 == -1) break;
if (ay[x[cnt1].second] == y[cnt2].first || az[x[cnt1].second] == z[cnt3].first) {there[x[cnt1].second] = 0; continue;}
if (az[y[cnt2].second] == z[cnt3].first || ax[y[cnt2].second] == x[cnt1].first) {there[y[cnt2].second] = 0; continue;}
if (ax[z[cnt3].second] == x[cnt1].first || ay[z[cnt3].second] == y[cnt2].first) {there[z[cnt3].second] = 0; continue;}
break;
}
if (cnt1 == -1) {cout << -1; return 0;}
else cout << x[cnt1].first + y[cnt2].first + z[cnt3].first;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
324 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 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 |
324 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 |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
324 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 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 |
324 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 |
748 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
3 ms |
596 KB |
Output is correct |
29 |
Correct |
3 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
3 ms |
592 KB |
Output is correct |
34 |
Correct |
3 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
72 ms |
11896 KB |
Output is correct |
12 |
Correct |
49 ms |
8032 KB |
Output is correct |
13 |
Correct |
48 ms |
9844 KB |
Output is correct |
14 |
Correct |
62 ms |
11880 KB |
Output is correct |
15 |
Correct |
58 ms |
11900 KB |
Output is correct |
16 |
Correct |
35 ms |
11776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
72 ms |
11896 KB |
Output is correct |
12 |
Correct |
49 ms |
8032 KB |
Output is correct |
13 |
Correct |
48 ms |
9844 KB |
Output is correct |
14 |
Correct |
62 ms |
11880 KB |
Output is correct |
15 |
Correct |
58 ms |
11900 KB |
Output is correct |
16 |
Correct |
35 ms |
11776 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
83 ms |
12020 KB |
Output is correct |
23 |
Correct |
66 ms |
11680 KB |
Output is correct |
24 |
Correct |
51 ms |
8788 KB |
Output is correct |
25 |
Correct |
72 ms |
12124 KB |
Output is correct |
26 |
Correct |
59 ms |
12012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
72 ms |
11896 KB |
Output is correct |
12 |
Correct |
49 ms |
8032 KB |
Output is correct |
13 |
Correct |
48 ms |
9844 KB |
Output is correct |
14 |
Correct |
62 ms |
11880 KB |
Output is correct |
15 |
Correct |
58 ms |
11900 KB |
Output is correct |
16 |
Correct |
35 ms |
11776 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
83 ms |
12020 KB |
Output is correct |
23 |
Correct |
66 ms |
11680 KB |
Output is correct |
24 |
Correct |
51 ms |
8788 KB |
Output is correct |
25 |
Correct |
72 ms |
12124 KB |
Output is correct |
26 |
Correct |
59 ms |
12012 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 |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
74 ms |
12032 KB |
Output is correct |
35 |
Correct |
69 ms |
11424 KB |
Output is correct |
36 |
Correct |
76 ms |
12544 KB |
Output is correct |
37 |
Correct |
77 ms |
12588 KB |
Output is correct |
38 |
Correct |
60 ms |
12364 KB |
Output is correct |
39 |
Correct |
35 ms |
7620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
72 ms |
11896 KB |
Output is correct |
12 |
Correct |
49 ms |
8032 KB |
Output is correct |
13 |
Correct |
48 ms |
9844 KB |
Output is correct |
14 |
Correct |
62 ms |
11880 KB |
Output is correct |
15 |
Correct |
58 ms |
11900 KB |
Output is correct |
16 |
Correct |
35 ms |
11776 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
83 ms |
12020 KB |
Output is correct |
23 |
Correct |
66 ms |
11680 KB |
Output is correct |
24 |
Correct |
51 ms |
8788 KB |
Output is correct |
25 |
Correct |
72 ms |
12124 KB |
Output is correct |
26 |
Correct |
59 ms |
12012 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 |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
74 ms |
12032 KB |
Output is correct |
35 |
Correct |
69 ms |
11424 KB |
Output is correct |
36 |
Correct |
76 ms |
12544 KB |
Output is correct |
37 |
Correct |
77 ms |
12588 KB |
Output is correct |
38 |
Correct |
60 ms |
12364 KB |
Output is correct |
39 |
Correct |
35 ms |
7620 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
2 ms |
596 KB |
Output is correct |
42 |
Correct |
2 ms |
596 KB |
Output is correct |
43 |
Correct |
2 ms |
652 KB |
Output is correct |
44 |
Correct |
81 ms |
13092 KB |
Output is correct |
45 |
Correct |
83 ms |
13052 KB |
Output is correct |
46 |
Correct |
85 ms |
13172 KB |
Output is correct |
47 |
Correct |
82 ms |
13132 KB |
Output is correct |
48 |
Correct |
69 ms |
12916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
324 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 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 |
324 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 |
748 KB |
Output is correct |
27 |
Correct |
2 ms |
596 KB |
Output is correct |
28 |
Correct |
3 ms |
596 KB |
Output is correct |
29 |
Correct |
3 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
3 ms |
592 KB |
Output is correct |
34 |
Correct |
3 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
596 KB |
Output is correct |
38 |
Correct |
3 ms |
596 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 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 |
72 ms |
11896 KB |
Output is correct |
51 |
Correct |
49 ms |
8032 KB |
Output is correct |
52 |
Correct |
48 ms |
9844 KB |
Output is correct |
53 |
Correct |
62 ms |
11880 KB |
Output is correct |
54 |
Correct |
58 ms |
11900 KB |
Output is correct |
55 |
Correct |
35 ms |
11776 KB |
Output is correct |
56 |
Correct |
0 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
328 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
324 KB |
Output is correct |
60 |
Correct |
2 ms |
468 KB |
Output is correct |
61 |
Correct |
83 ms |
12020 KB |
Output is correct |
62 |
Correct |
66 ms |
11680 KB |
Output is correct |
63 |
Correct |
51 ms |
8788 KB |
Output is correct |
64 |
Correct |
72 ms |
12124 KB |
Output is correct |
65 |
Correct |
59 ms |
12012 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 |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
320 KB |
Output is correct |
70 |
Correct |
3 ms |
596 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
74 ms |
12032 KB |
Output is correct |
74 |
Correct |
69 ms |
11424 KB |
Output is correct |
75 |
Correct |
76 ms |
12544 KB |
Output is correct |
76 |
Correct |
77 ms |
12588 KB |
Output is correct |
77 |
Correct |
60 ms |
12364 KB |
Output is correct |
78 |
Correct |
35 ms |
7620 KB |
Output is correct |
79 |
Correct |
2 ms |
468 KB |
Output is correct |
80 |
Correct |
2 ms |
596 KB |
Output is correct |
81 |
Correct |
2 ms |
596 KB |
Output is correct |
82 |
Correct |
2 ms |
652 KB |
Output is correct |
83 |
Correct |
81 ms |
13092 KB |
Output is correct |
84 |
Correct |
83 ms |
13052 KB |
Output is correct |
85 |
Correct |
85 ms |
13172 KB |
Output is correct |
86 |
Correct |
82 ms |
13132 KB |
Output is correct |
87 |
Correct |
69 ms |
12916 KB |
Output is correct |
88 |
Correct |
79 ms |
14832 KB |
Output is correct |
89 |
Correct |
102 ms |
14924 KB |
Output is correct |
90 |
Correct |
83 ms |
14904 KB |
Output is correct |
91 |
Correct |
89 ms |
14844 KB |
Output is correct |
92 |
Correct |
80 ms |
13448 KB |
Output is correct |
93 |
Correct |
79 ms |
13684 KB |
Output is correct |
94 |
Correct |
82 ms |
13624 KB |
Output is correct |
95 |
Correct |
76 ms |
14796 KB |
Output is correct |
96 |
Correct |
83 ms |
14896 KB |
Output is correct |
97 |
Correct |
57 ms |
14848 KB |
Output is correct |
98 |
Correct |
43 ms |
13556 KB |
Output is correct |
99 |
Correct |
75 ms |
13560 KB |
Output is correct |