답안 #696275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696275 2023-02-06T04:54:16 Z hpesoj Team Contest (JOI22_team) C++17
100 / 100
96 ms 7860 KB
#include <bits/stdc++.h>
#define pi pair <int, int>
#define ppi pair <pi, int>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
 
int n, t, c, f, g, h, X[150005], Y[150005], Z[150005];
vector <pi> x, y, z;
bool removed[150005];
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

 
signed main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> f >> g >> h;
		X[i] = f, Y[i] = g, Z[i] = h;
		x.pb({f, i}), y.pb({g, i}), z.pb({h, i});
	}
	sort(all(x)), sort(all(y)), sort(all(z));
	while(1){
		while(!x.empty() and removed[x.back().se]) x.pop_back();
		while(!y.empty() and removed[y.back().se]) y.pop_back();
		while(!z.empty() and removed[z.back().se]) z.pop_back();
		int i, j, k;
		if(x.empty() or y.empty() or z.empty()){
			cout << -1;
			break;
		}
		else i = x.back().se, j = y.back().se, k = z.back().se;
		if(i == j and j == k) x.pop_back(), y.pop_back(), z.pop_back(), removed[i] = 1;
		else if(i == j) x.pop_back(), y.pop_back(), removed[i] = 1;
		else if(i == k) x.pop_back(), z.pop_back(), removed[i] = 1;
		else if(j == k) y.pop_back(), z.pop_back(), removed[j] = 1;
		else{
			bool b = 0;
			if(Y[i] == y.back().fi or Z[i] == z.back().fi) b = 1, removed[i] = 1, x.pop_back();
			if(X[j] == x.back().fi or Z[j] == z.back().fi) b = 1, removed[j] = 1, y.pop_back();
			if(X[k] == x.back().fi or Y[k] == y.back().fi) b = 1, removed[k] = 1, z.pop_back();
			if(b) continue;
			cout << x.back().fi + y.back().fi + z.back().fi;
			break;
		}
	}
}
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 1 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 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 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 1 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 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 0 ms 340 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 416 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 63 ms 6096 KB Output is correct
12 Correct 50 ms 3996 KB Output is correct
13 Correct 44 ms 4844 KB Output is correct
14 Correct 63 ms 6148 KB Output is correct
15 Correct 58 ms 6024 KB Output is correct
16 Correct 37 ms 6096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 63 ms 6096 KB Output is correct
12 Correct 50 ms 3996 KB Output is correct
13 Correct 44 ms 4844 KB Output is correct
14 Correct 63 ms 6148 KB Output is correct
15 Correct 58 ms 6024 KB Output is correct
16 Correct 37 ms 6096 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 85 ms 6916 KB Output is correct
23 Correct 69 ms 6092 KB Output is correct
24 Correct 51 ms 4796 KB Output is correct
25 Correct 72 ms 6964 KB Output is correct
26 Correct 62 ms 6648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 63 ms 6096 KB Output is correct
12 Correct 50 ms 3996 KB Output is correct
13 Correct 44 ms 4844 KB Output is correct
14 Correct 63 ms 6148 KB Output is correct
15 Correct 58 ms 6024 KB Output is correct
16 Correct 37 ms 6096 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 85 ms 6916 KB Output is correct
23 Correct 69 ms 6092 KB Output is correct
24 Correct 51 ms 4796 KB Output is correct
25 Correct 72 ms 6964 KB Output is correct
26 Correct 62 ms 6648 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 332 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 69 ms 6944 KB Output is correct
35 Correct 70 ms 6964 KB Output is correct
36 Correct 74 ms 6884 KB Output is correct
37 Correct 78 ms 6320 KB Output is correct
38 Correct 71 ms 7028 KB Output is correct
39 Correct 36 ms 3700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 63 ms 6096 KB Output is correct
12 Correct 50 ms 3996 KB Output is correct
13 Correct 44 ms 4844 KB Output is correct
14 Correct 63 ms 6148 KB Output is correct
15 Correct 58 ms 6024 KB Output is correct
16 Correct 37 ms 6096 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 85 ms 6916 KB Output is correct
23 Correct 69 ms 6092 KB Output is correct
24 Correct 51 ms 4796 KB Output is correct
25 Correct 72 ms 6964 KB Output is correct
26 Correct 62 ms 6648 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 332 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 69 ms 6944 KB Output is correct
35 Correct 70 ms 6964 KB Output is correct
36 Correct 74 ms 6884 KB Output is correct
37 Correct 78 ms 6320 KB Output is correct
38 Correct 71 ms 7028 KB Output is correct
39 Correct 36 ms 3700 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 464 KB Output is correct
44 Correct 84 ms 7296 KB Output is correct
45 Correct 94 ms 7536 KB Output is correct
46 Correct 82 ms 7392 KB Output is correct
47 Correct 80 ms 7616 KB Output is correct
48 Correct 69 ms 7384 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 1 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 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 0 ms 340 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 416 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 63 ms 6096 KB Output is correct
51 Correct 50 ms 3996 KB Output is correct
52 Correct 44 ms 4844 KB Output is correct
53 Correct 63 ms 6148 KB Output is correct
54 Correct 58 ms 6024 KB Output is correct
55 Correct 37 ms 6096 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 85 ms 6916 KB Output is correct
62 Correct 69 ms 6092 KB Output is correct
63 Correct 51 ms 4796 KB Output is correct
64 Correct 72 ms 6964 KB Output is correct
65 Correct 62 ms 6648 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 332 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 69 ms 6944 KB Output is correct
74 Correct 70 ms 6964 KB Output is correct
75 Correct 74 ms 6884 KB Output is correct
76 Correct 78 ms 6320 KB Output is correct
77 Correct 71 ms 7028 KB Output is correct
78 Correct 36 ms 3700 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 2 ms 468 KB Output is correct
81 Correct 2 ms 468 KB Output is correct
82 Correct 2 ms 464 KB Output is correct
83 Correct 84 ms 7296 KB Output is correct
84 Correct 94 ms 7536 KB Output is correct
85 Correct 82 ms 7392 KB Output is correct
86 Correct 80 ms 7616 KB Output is correct
87 Correct 69 ms 7384 KB Output is correct
88 Correct 83 ms 7776 KB Output is correct
89 Correct 96 ms 7736 KB Output is correct
90 Correct 85 ms 7668 KB Output is correct
91 Correct 96 ms 7652 KB Output is correct
92 Correct 82 ms 7756 KB Output is correct
93 Correct 94 ms 7736 KB Output is correct
94 Correct 87 ms 7860 KB Output is correct
95 Correct 79 ms 7684 KB Output is correct
96 Correct 78 ms 7660 KB Output is correct
97 Correct 59 ms 7644 KB Output is correct
98 Correct 48 ms 7808 KB Output is correct
99 Correct 70 ms 7728 KB Output is correct