#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define isz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)
const int N=15e4+10;
int n, x[N], y[N], z[N];
map<pair<int, int>, set<int>> xy, yz, zx;
multiset<int> sx, sy, sz;
void solve(){
cin >> n;
for (int i=1; i<=n; ++i){
cin >> x[i] >> y[i] >> z[i];
xy[{x[i], y[i]}].insert(i);
yz[{y[i], z[i]}].insert(i);
zx[{z[i], x[i]}].insert(i);
sx.insert(x[i]);
sy.insert(y[i]);
sz.insert(z[i]);
}
while (sx.size()){
int mx=*sx.rbegin();
int my=*sy.rbegin();
int mz=*sz.rbegin();
bool stop=1;
if (xy.count({mx, my}) && xy[{mx, my}].size()){
for (int i:xy[{mx, my}]){
sx.erase(sx.find(x[i]));
sy.erase(sy.find(y[i]));
sz.erase(sz.find(z[i]));
yz[{y[i], z[i]}].erase(i);
zx[{z[i], x[i]}].erase(i);
}
xy[{mx, my}].clear();
stop=0;
}
if (yz.count({my, mz}) && yz[{my, mz}].size()){
for (int i:yz[{my, mz}]){
sx.erase(sx.find(x[i]));
sy.erase(sy.find(y[i]));
sz.erase(sz.find(z[i]));
zx[{z[i], x[i]}].erase(i);
xy[{x[i], y[i]}].erase(i);
}
yz[{my, mz}].clear();
stop=0;
}
if (zx.count({mz, mx}) && zx[{mz, mx}].size()){
for (int i:zx[{mz, mx}]){
sx.erase(sx.find(x[i]));
sy.erase(sy.find(y[i]));
sz.erase(sz.find(z[i]));
xy[{x[i], y[i]}].erase(i);
yz[{y[i], z[i]}].erase(i);
}
zx[{mz, mx}].clear();
stop=0;
}
if (stop) break;
}
if (sx.size()) cout << (*sx.rbegin()+*sy.rbegin()+*sz.rbegin());
else cout << -1;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int ntests=1;
// cin >> ntests;
for (int i=1; i<=ntests; ++i) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2564 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2460 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2564 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2460 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
7 ms |
5132 KB |
Output is correct |
27 |
Correct |
8 ms |
4896 KB |
Output is correct |
28 |
Correct |
8 ms |
4956 KB |
Output is correct |
29 |
Correct |
10 ms |
4828 KB |
Output is correct |
30 |
Correct |
8 ms |
4188 KB |
Output is correct |
31 |
Correct |
7 ms |
4952 KB |
Output is correct |
32 |
Correct |
9 ms |
4444 KB |
Output is correct |
33 |
Correct |
7 ms |
4188 KB |
Output is correct |
34 |
Correct |
9 ms |
4952 KB |
Output is correct |
35 |
Correct |
2 ms |
2908 KB |
Output is correct |
36 |
Correct |
2 ms |
2908 KB |
Output is correct |
37 |
Correct |
5 ms |
4444 KB |
Output is correct |
38 |
Correct |
8 ms |
4444 KB |
Output is correct |
39 |
Correct |
4 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2508 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2512 KB |
Output is correct |
11 |
Correct |
371 ms |
47128 KB |
Output is correct |
12 |
Correct |
243 ms |
32220 KB |
Output is correct |
13 |
Correct |
241 ms |
39160 KB |
Output is correct |
14 |
Correct |
436 ms |
46980 KB |
Output is correct |
15 |
Correct |
308 ms |
47120 KB |
Output is correct |
16 |
Correct |
219 ms |
47116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2508 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2512 KB |
Output is correct |
11 |
Correct |
371 ms |
47128 KB |
Output is correct |
12 |
Correct |
243 ms |
32220 KB |
Output is correct |
13 |
Correct |
241 ms |
39160 KB |
Output is correct |
14 |
Correct |
436 ms |
46980 KB |
Output is correct |
15 |
Correct |
308 ms |
47120 KB |
Output is correct |
16 |
Correct |
219 ms |
47116 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
3 ms |
3164 KB |
Output is correct |
22 |
Correct |
493 ms |
47316 KB |
Output is correct |
23 |
Correct |
443 ms |
46212 KB |
Output is correct |
24 |
Correct |
346 ms |
35008 KB |
Output is correct |
25 |
Correct |
619 ms |
47364 KB |
Output is correct |
26 |
Correct |
317 ms |
47184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2508 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2512 KB |
Output is correct |
11 |
Correct |
371 ms |
47128 KB |
Output is correct |
12 |
Correct |
243 ms |
32220 KB |
Output is correct |
13 |
Correct |
241 ms |
39160 KB |
Output is correct |
14 |
Correct |
436 ms |
46980 KB |
Output is correct |
15 |
Correct |
308 ms |
47120 KB |
Output is correct |
16 |
Correct |
219 ms |
47116 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
3 ms |
3164 KB |
Output is correct |
22 |
Correct |
493 ms |
47316 KB |
Output is correct |
23 |
Correct |
443 ms |
46212 KB |
Output is correct |
24 |
Correct |
346 ms |
35008 KB |
Output is correct |
25 |
Correct |
619 ms |
47364 KB |
Output is correct |
26 |
Correct |
317 ms |
47184 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
9 ms |
4440 KB |
Output is correct |
32 |
Correct |
2 ms |
2904 KB |
Output is correct |
33 |
Correct |
2 ms |
3000 KB |
Output is correct |
34 |
Correct |
733 ms |
69088 KB |
Output is correct |
35 |
Correct |
812 ms |
60588 KB |
Output is correct |
36 |
Correct |
977 ms |
62960 KB |
Output is correct |
37 |
Correct |
1040 ms |
61700 KB |
Output is correct |
38 |
Correct |
449 ms |
46884 KB |
Output is correct |
39 |
Correct |
209 ms |
39416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2508 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2512 KB |
Output is correct |
11 |
Correct |
371 ms |
47128 KB |
Output is correct |
12 |
Correct |
243 ms |
32220 KB |
Output is correct |
13 |
Correct |
241 ms |
39160 KB |
Output is correct |
14 |
Correct |
436 ms |
46980 KB |
Output is correct |
15 |
Correct |
308 ms |
47120 KB |
Output is correct |
16 |
Correct |
219 ms |
47116 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
3 ms |
3164 KB |
Output is correct |
22 |
Correct |
493 ms |
47316 KB |
Output is correct |
23 |
Correct |
443 ms |
46212 KB |
Output is correct |
24 |
Correct |
346 ms |
35008 KB |
Output is correct |
25 |
Correct |
619 ms |
47364 KB |
Output is correct |
26 |
Correct |
317 ms |
47184 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
9 ms |
4440 KB |
Output is correct |
32 |
Correct |
2 ms |
2904 KB |
Output is correct |
33 |
Correct |
2 ms |
3000 KB |
Output is correct |
34 |
Correct |
733 ms |
69088 KB |
Output is correct |
35 |
Correct |
812 ms |
60588 KB |
Output is correct |
36 |
Correct |
977 ms |
62960 KB |
Output is correct |
37 |
Correct |
1040 ms |
61700 KB |
Output is correct |
38 |
Correct |
449 ms |
46884 KB |
Output is correct |
39 |
Correct |
209 ms |
39416 KB |
Output is correct |
40 |
Correct |
9 ms |
4200 KB |
Output is correct |
41 |
Correct |
10 ms |
4828 KB |
Output is correct |
42 |
Correct |
7 ms |
4444 KB |
Output is correct |
43 |
Correct |
9 ms |
4444 KB |
Output is correct |
44 |
Correct |
1078 ms |
97388 KB |
Output is correct |
45 |
Correct |
1381 ms |
83524 KB |
Output is correct |
46 |
Correct |
1369 ms |
88020 KB |
Output is correct |
47 |
Correct |
1545 ms |
82208 KB |
Output is correct |
48 |
Correct |
568 ms |
49612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2564 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2460 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
7 ms |
5132 KB |
Output is correct |
27 |
Correct |
8 ms |
4896 KB |
Output is correct |
28 |
Correct |
8 ms |
4956 KB |
Output is correct |
29 |
Correct |
10 ms |
4828 KB |
Output is correct |
30 |
Correct |
8 ms |
4188 KB |
Output is correct |
31 |
Correct |
7 ms |
4952 KB |
Output is correct |
32 |
Correct |
9 ms |
4444 KB |
Output is correct |
33 |
Correct |
7 ms |
4188 KB |
Output is correct |
34 |
Correct |
9 ms |
4952 KB |
Output is correct |
35 |
Correct |
2 ms |
2908 KB |
Output is correct |
36 |
Correct |
2 ms |
2908 KB |
Output is correct |
37 |
Correct |
5 ms |
4444 KB |
Output is correct |
38 |
Correct |
8 ms |
4444 KB |
Output is correct |
39 |
Correct |
4 ms |
3164 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2508 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2392 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2512 KB |
Output is correct |
50 |
Correct |
371 ms |
47128 KB |
Output is correct |
51 |
Correct |
243 ms |
32220 KB |
Output is correct |
52 |
Correct |
241 ms |
39160 KB |
Output is correct |
53 |
Correct |
436 ms |
46980 KB |
Output is correct |
54 |
Correct |
308 ms |
47120 KB |
Output is correct |
55 |
Correct |
219 ms |
47116 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
1 ms |
2392 KB |
Output is correct |
58 |
Correct |
1 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2652 KB |
Output is correct |
60 |
Correct |
3 ms |
3164 KB |
Output is correct |
61 |
Correct |
493 ms |
47316 KB |
Output is correct |
62 |
Correct |
443 ms |
46212 KB |
Output is correct |
63 |
Correct |
346 ms |
35008 KB |
Output is correct |
64 |
Correct |
619 ms |
47364 KB |
Output is correct |
65 |
Correct |
317 ms |
47184 KB |
Output is correct |
66 |
Correct |
1 ms |
2648 KB |
Output is correct |
67 |
Correct |
1 ms |
2652 KB |
Output is correct |
68 |
Correct |
1 ms |
2648 KB |
Output is correct |
69 |
Correct |
1 ms |
2648 KB |
Output is correct |
70 |
Correct |
9 ms |
4440 KB |
Output is correct |
71 |
Correct |
2 ms |
2904 KB |
Output is correct |
72 |
Correct |
2 ms |
3000 KB |
Output is correct |
73 |
Correct |
733 ms |
69088 KB |
Output is correct |
74 |
Correct |
812 ms |
60588 KB |
Output is correct |
75 |
Correct |
977 ms |
62960 KB |
Output is correct |
76 |
Correct |
1040 ms |
61700 KB |
Output is correct |
77 |
Correct |
449 ms |
46884 KB |
Output is correct |
78 |
Correct |
209 ms |
39416 KB |
Output is correct |
79 |
Correct |
9 ms |
4200 KB |
Output is correct |
80 |
Correct |
10 ms |
4828 KB |
Output is correct |
81 |
Correct |
7 ms |
4444 KB |
Output is correct |
82 |
Correct |
9 ms |
4444 KB |
Output is correct |
83 |
Correct |
1078 ms |
97388 KB |
Output is correct |
84 |
Correct |
1381 ms |
83524 KB |
Output is correct |
85 |
Correct |
1369 ms |
88020 KB |
Output is correct |
86 |
Correct |
1545 ms |
82208 KB |
Output is correct |
87 |
Correct |
568 ms |
49612 KB |
Output is correct |
88 |
Correct |
1052 ms |
99364 KB |
Output is correct |
89 |
Correct |
1209 ms |
97248 KB |
Output is correct |
90 |
Correct |
1112 ms |
99332 KB |
Output is correct |
91 |
Correct |
1245 ms |
95904 KB |
Output is correct |
92 |
Correct |
1122 ms |
96220 KB |
Output is correct |
93 |
Correct |
1324 ms |
96392 KB |
Output is correct |
94 |
Correct |
1444 ms |
92872 KB |
Output is correct |
95 |
Correct |
740 ms |
74548 KB |
Output is correct |
96 |
Correct |
690 ms |
99328 KB |
Output is correct |
97 |
Correct |
311 ms |
50000 KB |
Output is correct |
98 |
Correct |
351 ms |
81648 KB |
Output is correct |
99 |
Correct |
374 ms |
81588 KB |
Output is correct |