답안 #927959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927959 2024-02-15T14:48:41 Z OAleksa Team Contest (JOI22_team) C++14
100 / 100
1119 ms 66060 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
const int N = 2e5 + 69;
int n, a[N], b[N], c[N], vis[N], u;
multiset<int> x, y, z;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	cin >> n;
  	multiset<tuple<int, int, int>> st1, st2, st3;
  	multiset<tuple<int, int, int, int>> ev;
  	for (int i = 1;i <= n;i++) {
  		cin >> a[i] >> b[i] >> c[i];
  		st1.insert({a[i], b[i], i});
  		st2.insert({a[i], c[i], i});
  		st3.insert({b[i], c[i], i});
  		ev.insert({a[i], b[i], c[i], i});
  		x.insert(a[i]);
  		y.insert(b[i]);
  		z.insert(c[i]);
  	}
  	while (!x.empty()) {
  		auto mx = *x.rbegin();
  		auto my = *y.rbegin();
  		auto mz = *z.rbegin();
  		auto u1 = st1.lower_bound({mx, my, -1});
  		auto u2 = st2.lower_bound({mx, mz, -1});
  		auto u3 = st3.lower_bound({my, mz, -1});
  		auto u4 = ev.lower_bound({mx, my, mx, -1});
  		if (u1 != st1.end() && get<0>(*u1) == mx && get<1>(*u1) == my) {
  			int i = get<2>(*u1);
  			x.erase(x.find(a[i]));
  			y.erase(y.find(b[i]));
  			z.erase(z.find(c[i]));
  			st1.erase(st1.find({a[i], b[i], i}));
  			st2.erase(st2.find({a[i], c[i], i}));
  			st3.erase(st3.find({b[i], c[i], i}));
  			ev.erase(ev.find({a[i], b[i], c[i], i}));
  			vis[i] = 1;
  		}
  		else if (u2 != st2.end() && get<0>(*u2) == mx && get<1>(*u2) == mz) {
  			int i = get<2>(*u2);
  			x.erase(x.find(a[i]));
  			y.erase(y.find(b[i]));
  			z.erase(z.find(c[i]));
  			st1.erase(st1.find({a[i], b[i], i}));
  			st2.erase(st2.find({a[i], c[i], i}));
  			st3.erase(st3.find({b[i], c[i], i}));
  			ev.erase(ev.find({a[i], b[i], c[i], i}));
  			vis[i] = 1;
  		}
  		else if (u3 != st3.end() && get<0>(*u3) == my && get<1>(*u3) == mz) {
  			int i = get<2>(*u3);
  			x.erase(x.find(a[i]));
  			y.erase(y.find(b[i]));
  			z.erase(z.find(c[i]));
  			st1.erase(st1.find({a[i], b[i], i}));
  			st2.erase(st2.find({a[i], c[i], i}));
  			st3.erase(st3.find({b[i], c[i], i}));
  			ev.erase(ev.find({a[i], b[i], c[i], i}));
  			vis[i] = 1;
  		}
  		else if (u4 != ev.end() && get<0>(*u4) == mx && get<1>(*u4) == my && get<2>(*u4) == mz) {
  			int i = get<3>(*u4);
  			x.erase(x.find(a[i]));
  			y.erase(y.find(b[i]));
  			z.erase(z.find(c[i]));
  			st1.erase(st1.find({a[i], b[i], i}));
  			st2.erase(st2.find({a[i], c[i], i}));
  			st3.erase(st3.find({b[i], c[i], i}));
  			ev.erase(ev.find({a[i], b[i], c[i], i}));
  			vis[i] = 1;
  		}
  		else
  			break;
  	}
  	int ans = -1;
  	int mx = 0, my = 0, mz = 0;
  	for (int i = 1;i <= n;i++) {
  		if (!vis[i]) {
  			u++;
  			mx = max(mx, a[i]);
  			my = max(my, b[i]);
  			mz = max(mz, c[i]);
  		}
  	}
  	if (u > 2)	
  		ans = mx + my + mz;
  	cout << ans << '\n';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2516 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2516 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 6 ms 4184 KB Output is correct
27 Correct 6 ms 4184 KB Output is correct
28 Correct 7 ms 4188 KB Output is correct
29 Correct 8 ms 4188 KB Output is correct
30 Correct 7 ms 3920 KB Output is correct
31 Correct 6 ms 4088 KB Output is correct
32 Correct 9 ms 3932 KB Output is correct
33 Correct 8 ms 3932 KB Output is correct
34 Correct 6 ms 4188 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 4 ms 3932 KB Output is correct
38 Correct 7 ms 4064 KB Output is correct
39 Correct 3 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2592 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 458 ms 62804 KB Output is correct
12 Correct 307 ms 42904 KB Output is correct
13 Correct 264 ms 52304 KB Output is correct
14 Correct 505 ms 62548 KB Output is correct
15 Correct 397 ms 62592 KB Output is correct
16 Correct 265 ms 62508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2592 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 458 ms 62804 KB Output is correct
12 Correct 307 ms 42904 KB Output is correct
13 Correct 264 ms 52304 KB Output is correct
14 Correct 505 ms 62548 KB Output is correct
15 Correct 397 ms 62592 KB Output is correct
16 Correct 265 ms 62508 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 3 ms 3164 KB Output is correct
22 Correct 650 ms 62812 KB Output is correct
23 Correct 579 ms 61012 KB Output is correct
24 Correct 448 ms 46028 KB Output is correct
25 Correct 709 ms 62712 KB Output is correct
26 Correct 424 ms 62736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2592 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 458 ms 62804 KB Output is correct
12 Correct 307 ms 42904 KB Output is correct
13 Correct 264 ms 52304 KB Output is correct
14 Correct 505 ms 62548 KB Output is correct
15 Correct 397 ms 62592 KB Output is correct
16 Correct 265 ms 62508 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 3 ms 3164 KB Output is correct
22 Correct 650 ms 62812 KB Output is correct
23 Correct 579 ms 61012 KB Output is correct
24 Correct 448 ms 46028 KB Output is correct
25 Correct 709 ms 62712 KB Output is correct
26 Correct 424 ms 62736 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 10 ms 4060 KB Output is correct
32 Correct 1 ms 2648 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 737 ms 60164 KB Output is correct
35 Correct 768 ms 57628 KB Output is correct
36 Correct 891 ms 63248 KB Output is correct
37 Correct 943 ms 62456 KB Output is correct
38 Correct 511 ms 61888 KB Output is correct
39 Correct 215 ms 38740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2592 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 458 ms 62804 KB Output is correct
12 Correct 307 ms 42904 KB Output is correct
13 Correct 264 ms 52304 KB Output is correct
14 Correct 505 ms 62548 KB Output is correct
15 Correct 397 ms 62592 KB Output is correct
16 Correct 265 ms 62508 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 3 ms 3164 KB Output is correct
22 Correct 650 ms 62812 KB Output is correct
23 Correct 579 ms 61012 KB Output is correct
24 Correct 448 ms 46028 KB Output is correct
25 Correct 709 ms 62712 KB Output is correct
26 Correct 424 ms 62736 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 10 ms 4060 KB Output is correct
32 Correct 1 ms 2648 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 737 ms 60164 KB Output is correct
35 Correct 768 ms 57628 KB Output is correct
36 Correct 891 ms 63248 KB Output is correct
37 Correct 943 ms 62456 KB Output is correct
38 Correct 511 ms 61888 KB Output is correct
39 Correct 215 ms 38740 KB Output is correct
40 Correct 5 ms 3416 KB Output is correct
41 Correct 6 ms 3932 KB Output is correct
42 Correct 4 ms 3932 KB Output is correct
43 Correct 6 ms 4060 KB Output is correct
44 Correct 914 ms 63244 KB Output is correct
45 Correct 1115 ms 63332 KB Output is correct
46 Correct 1099 ms 64164 KB Output is correct
47 Correct 1119 ms 63876 KB Output is correct
48 Correct 588 ms 64140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 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 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2516 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 6 ms 4184 KB Output is correct
27 Correct 6 ms 4184 KB Output is correct
28 Correct 7 ms 4188 KB Output is correct
29 Correct 8 ms 4188 KB Output is correct
30 Correct 7 ms 3920 KB Output is correct
31 Correct 6 ms 4088 KB Output is correct
32 Correct 9 ms 3932 KB Output is correct
33 Correct 8 ms 3932 KB Output is correct
34 Correct 6 ms 4188 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 4 ms 3932 KB Output is correct
38 Correct 7 ms 4064 KB Output is correct
39 Correct 3 ms 3164 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2516 KB Output is correct
42 Correct 1 ms 2392 KB Output is correct
43 Correct 1 ms 2392 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 0 ms 2392 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 1 ms 2592 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 458 ms 62804 KB Output is correct
51 Correct 307 ms 42904 KB Output is correct
52 Correct 264 ms 52304 KB Output is correct
53 Correct 505 ms 62548 KB Output is correct
54 Correct 397 ms 62592 KB Output is correct
55 Correct 265 ms 62508 KB Output is correct
56 Correct 1 ms 2392 KB Output is correct
57 Correct 1 ms 2648 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 3 ms 3164 KB Output is correct
61 Correct 650 ms 62812 KB Output is correct
62 Correct 579 ms 61012 KB Output is correct
63 Correct 448 ms 46028 KB Output is correct
64 Correct 709 ms 62712 KB Output is correct
65 Correct 424 ms 62736 KB Output is correct
66 Correct 1 ms 2396 KB Output is correct
67 Correct 1 ms 2396 KB Output is correct
68 Correct 1 ms 2396 KB Output is correct
69 Correct 1 ms 2648 KB Output is correct
70 Correct 10 ms 4060 KB Output is correct
71 Correct 1 ms 2648 KB Output is correct
72 Correct 2 ms 2652 KB Output is correct
73 Correct 737 ms 60164 KB Output is correct
74 Correct 768 ms 57628 KB Output is correct
75 Correct 891 ms 63248 KB Output is correct
76 Correct 943 ms 62456 KB Output is correct
77 Correct 511 ms 61888 KB Output is correct
78 Correct 215 ms 38740 KB Output is correct
79 Correct 5 ms 3416 KB Output is correct
80 Correct 6 ms 3932 KB Output is correct
81 Correct 4 ms 3932 KB Output is correct
82 Correct 6 ms 4060 KB Output is correct
83 Correct 914 ms 63244 KB Output is correct
84 Correct 1115 ms 63332 KB Output is correct
85 Correct 1099 ms 64164 KB Output is correct
86 Correct 1119 ms 63876 KB Output is correct
87 Correct 588 ms 64140 KB Output is correct
88 Correct 643 ms 65528 KB Output is correct
89 Correct 731 ms 65872 KB Output is correct
90 Correct 747 ms 65860 KB Output is correct
91 Correct 837 ms 66060 KB Output is correct
92 Correct 819 ms 64528 KB Output is correct
93 Correct 840 ms 64748 KB Output is correct
94 Correct 911 ms 64672 KB Output is correct
95 Correct 555 ms 65616 KB Output is correct
96 Correct 349 ms 65872 KB Output is correct
97 Correct 279 ms 65912 KB Output is correct
98 Correct 253 ms 64332 KB Output is correct
99 Correct 290 ms 64340 KB Output is correct