#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
using namespace std;
const int64_t INF = (int64_t) 1e18 + 777;
const int64_t mINF = 2500 + 5;
const int64_t MOD = 1e9 + 9;
const int nbit = 11;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
struct Thing
{
int x;
int y;
int z;
Thing(int x_, int y_, int z_) : x(x_), y(y_), z(z_) {}
};
struct Solution
{
Solution() {}
void solve()
{
int n;
cin >> n;
vector<Thing> v(n, Thing(-1, -1, -1));
set<pair<int, int> > a;
set<pair<int, int> > b;
set<pair<int, int> > c;
for(int i = 0; i < n; i++)
{
cin >> v[i].x >> v[i].y >> v[i].z;
a.insert(make_pair(-v[i].x, i));
b.insert(make_pair(-v[i].y, i));
c.insert(make_pair(-v[i].z, i));
}
int ans = -1;
for(int t = 0; t < n; t++)
{
int i = a.begin()->second;
int j = b.begin()->second;
int k = c.begin()->second;
int max_x = v[i].x;
int max_y = v[j].y;
int max_z = v[k].z;
if(v[i].y == max_y || v[i].z == max_z)
{
a.erase(make_pair(-v[i].x, i));
b.erase(make_pair(-v[i].y, i));
c.erase(make_pair(-v[i].z, i));
continue;
}
if(v[j].x == max_x || v[j].z == max_z)
{
a.erase(make_pair(-v[j].x, j));
b.erase(make_pair(-v[j].y, j));
c.erase(make_pair(-v[j].z, j));
continue;
}
if(v[k].x == max_x || v[k].y == max_y)
{
a.erase(make_pair(-v[k].x, k));
b.erase(make_pair(-v[k].y, k));
c.erase(make_pair(-v[k].z, k));
continue;
}
ans = v[i].x + v[j].y + v[k].z;
break;
}
cout << ans << "\n";
}
int modsub(int t1, int t2)
{
int res = t1 - t2;
if(res < 0) res += MOD;
return res;
}
int modadd(int t1, int t2)
{
int res = t1 + t2;
if(res >= MOD) res -= MOD;
return res;
}
int modmul(int t1, int t2)
{
int64_t res = 1LL * t1 * t2;
return (res % MOD);
}
bool BIT(int& mask, int& j)
{
return (mask & MASK(j));
}
int MASK(int j)
{
return (1 << j);
}
};
void __startup()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
}
int main()
{
__startup();
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
Solution().solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 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 |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
316 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 |
0 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 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 |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
316 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 |
980 KB |
Output is correct |
29 |
Correct |
6 ms |
1036 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
852 KB |
Output is correct |
32 |
Correct |
5 ms |
968 KB |
Output is correct |
33 |
Correct |
5 ms |
980 KB |
Output is correct |
34 |
Correct |
4 ms |
972 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
980 KB |
Output is correct |
38 |
Correct |
4 ms |
972 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
24024 KB |
Output is correct |
12 |
Correct |
123 ms |
16084 KB |
Output is correct |
13 |
Correct |
106 ms |
19852 KB |
Output is correct |
14 |
Correct |
196 ms |
24012 KB |
Output is correct |
15 |
Correct |
164 ms |
24064 KB |
Output is correct |
16 |
Correct |
150 ms |
23960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
24024 KB |
Output is correct |
12 |
Correct |
123 ms |
16084 KB |
Output is correct |
13 |
Correct |
106 ms |
19852 KB |
Output is correct |
14 |
Correct |
196 ms |
24012 KB |
Output is correct |
15 |
Correct |
164 ms |
24064 KB |
Output is correct |
16 |
Correct |
150 ms |
23960 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 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 |
182 ms |
24248 KB |
Output is correct |
23 |
Correct |
207 ms |
23448 KB |
Output is correct |
24 |
Correct |
165 ms |
17608 KB |
Output is correct |
25 |
Correct |
274 ms |
24300 KB |
Output is correct |
26 |
Correct |
180 ms |
24192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
24024 KB |
Output is correct |
12 |
Correct |
123 ms |
16084 KB |
Output is correct |
13 |
Correct |
106 ms |
19852 KB |
Output is correct |
14 |
Correct |
196 ms |
24012 KB |
Output is correct |
15 |
Correct |
164 ms |
24064 KB |
Output is correct |
16 |
Correct |
150 ms |
23960 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 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 |
182 ms |
24248 KB |
Output is correct |
23 |
Correct |
207 ms |
23448 KB |
Output is correct |
24 |
Correct |
165 ms |
17608 KB |
Output is correct |
25 |
Correct |
274 ms |
24300 KB |
Output is correct |
26 |
Correct |
180 ms |
24192 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
976 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
456 KB |
Output is correct |
34 |
Correct |
238 ms |
23516 KB |
Output is correct |
35 |
Correct |
260 ms |
22424 KB |
Output is correct |
36 |
Correct |
306 ms |
24612 KB |
Output is correct |
37 |
Correct |
351 ms |
24652 KB |
Output is correct |
38 |
Correct |
212 ms |
24164 KB |
Output is correct |
39 |
Correct |
91 ms |
14936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
166 ms |
24024 KB |
Output is correct |
12 |
Correct |
123 ms |
16084 KB |
Output is correct |
13 |
Correct |
106 ms |
19852 KB |
Output is correct |
14 |
Correct |
196 ms |
24012 KB |
Output is correct |
15 |
Correct |
164 ms |
24064 KB |
Output is correct |
16 |
Correct |
150 ms |
23960 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 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 |
182 ms |
24248 KB |
Output is correct |
23 |
Correct |
207 ms |
23448 KB |
Output is correct |
24 |
Correct |
165 ms |
17608 KB |
Output is correct |
25 |
Correct |
274 ms |
24300 KB |
Output is correct |
26 |
Correct |
180 ms |
24192 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
976 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
456 KB |
Output is correct |
34 |
Correct |
238 ms |
23516 KB |
Output is correct |
35 |
Correct |
260 ms |
22424 KB |
Output is correct |
36 |
Correct |
306 ms |
24612 KB |
Output is correct |
37 |
Correct |
351 ms |
24652 KB |
Output is correct |
38 |
Correct |
212 ms |
24164 KB |
Output is correct |
39 |
Correct |
91 ms |
14936 KB |
Output is correct |
40 |
Correct |
3 ms |
724 KB |
Output is correct |
41 |
Correct |
4 ms |
976 KB |
Output is correct |
42 |
Correct |
3 ms |
980 KB |
Output is correct |
43 |
Correct |
4 ms |
980 KB |
Output is correct |
44 |
Correct |
397 ms |
25164 KB |
Output is correct |
45 |
Correct |
398 ms |
25296 KB |
Output is correct |
46 |
Correct |
411 ms |
25468 KB |
Output is correct |
47 |
Correct |
408 ms |
25252 KB |
Output is correct |
48 |
Correct |
243 ms |
25116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 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 |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
316 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 |
980 KB |
Output is correct |
29 |
Correct |
6 ms |
1036 KB |
Output is correct |
30 |
Correct |
3 ms |
724 KB |
Output is correct |
31 |
Correct |
4 ms |
852 KB |
Output is correct |
32 |
Correct |
5 ms |
968 KB |
Output is correct |
33 |
Correct |
5 ms |
980 KB |
Output is correct |
34 |
Correct |
4 ms |
972 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
980 KB |
Output is correct |
38 |
Correct |
4 ms |
972 KB |
Output is correct |
39 |
Correct |
2 ms |
596 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
320 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 |
0 ms |
324 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
166 ms |
24024 KB |
Output is correct |
51 |
Correct |
123 ms |
16084 KB |
Output is correct |
52 |
Correct |
106 ms |
19852 KB |
Output is correct |
53 |
Correct |
196 ms |
24012 KB |
Output is correct |
54 |
Correct |
164 ms |
24064 KB |
Output is correct |
55 |
Correct |
150 ms |
23960 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
1 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 |
182 ms |
24248 KB |
Output is correct |
62 |
Correct |
207 ms |
23448 KB |
Output is correct |
63 |
Correct |
165 ms |
17608 KB |
Output is correct |
64 |
Correct |
274 ms |
24300 KB |
Output is correct |
65 |
Correct |
180 ms |
24192 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
320 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
5 ms |
976 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
1 ms |
456 KB |
Output is correct |
73 |
Correct |
238 ms |
23516 KB |
Output is correct |
74 |
Correct |
260 ms |
22424 KB |
Output is correct |
75 |
Correct |
306 ms |
24612 KB |
Output is correct |
76 |
Correct |
351 ms |
24652 KB |
Output is correct |
77 |
Correct |
212 ms |
24164 KB |
Output is correct |
78 |
Correct |
91 ms |
14936 KB |
Output is correct |
79 |
Correct |
3 ms |
724 KB |
Output is correct |
80 |
Correct |
4 ms |
976 KB |
Output is correct |
81 |
Correct |
3 ms |
980 KB |
Output is correct |
82 |
Correct |
4 ms |
980 KB |
Output is correct |
83 |
Correct |
397 ms |
25164 KB |
Output is correct |
84 |
Correct |
398 ms |
25296 KB |
Output is correct |
85 |
Correct |
411 ms |
25468 KB |
Output is correct |
86 |
Correct |
408 ms |
25252 KB |
Output is correct |
87 |
Correct |
243 ms |
25116 KB |
Output is correct |
88 |
Correct |
383 ms |
27004 KB |
Output is correct |
89 |
Correct |
347 ms |
27116 KB |
Output is correct |
90 |
Correct |
336 ms |
27080 KB |
Output is correct |
91 |
Correct |
357 ms |
27132 KB |
Output is correct |
92 |
Correct |
362 ms |
25548 KB |
Output is correct |
93 |
Correct |
372 ms |
25944 KB |
Output is correct |
94 |
Correct |
470 ms |
25804 KB |
Output is correct |
95 |
Correct |
265 ms |
26964 KB |
Output is correct |
96 |
Correct |
199 ms |
27072 KB |
Output is correct |
97 |
Correct |
162 ms |
27304 KB |
Output is correct |
98 |
Correct |
112 ms |
25728 KB |
Output is correct |
99 |
Correct |
135 ms |
25672 KB |
Output is correct |