답안 #696157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696157 2023-02-05T16:28:13 Z hpesoj Team Contest (JOI22_team) C++17
100 / 100
117 ms 15664 KB
#include <bits/stdc++.h>
#define int long long
#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());
/*int randnums[200005];
void gen(){
	for(int i = 0; i < 200005; i++){
		randnums[i] = rng() / 200005 + 1;
		//cout << randnums[i] << '\n';
	}
}*/

signed main(){
	ios::sync_with_stdio(0), cin.tie(0);
	memset(removed, 0, sizeof(removed));
	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();
		if(x.empty() or y.empty() or z.empty()){
			cout << -1;
			break;
		}
		int i = -1, j = -1, k = -1;
		if(!x.empty()){
			i = x.back().se;
			//cout << x.back().fi << ' ' << i << ' ';
		}
		if(!y.empty()){
			j = y.back().se;
			//cout << y.back().fi << ' ' << j << ' ';
		}
		if(!z.empty()){
			k = z.back().se;
			//cout << z.back().fi << ' ' << k << ' ';
		}
		//cout << '\n';
		if(i == j and j == k and i != -1) x.pop_back(), y.pop_back(), z.pop_back(), removed[i] = 1;
		else if(i == j and i != -1) x.pop_back(), y.pop_back(), removed[i] = 1;
		else if(i == k and i != -1) x.pop_back(), z.pop_back(), removed[i] = 1;
		else if(j == k and j != -1) 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;
			//cout << '\n' << i << ' ' << j << ' ' << k;
			break;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 484 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 480 KB Output is correct
18 Correct 1 ms 476 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 476 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 484 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 480 KB Output is correct
18 Correct 1 ms 476 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 476 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 3 ms 852 KB Output is correct
28 Correct 3 ms 872 KB Output is correct
29 Correct 3 ms 852 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 3 ms 852 KB Output is correct
32 Correct 3 ms 852 KB Output is correct
33 Correct 2 ms 852 KB Output is correct
34 Correct 3 ms 852 KB Output is correct
35 Correct 1 ms 480 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 3 ms 852 KB Output is correct
38 Correct 3 ms 852 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 84 ms 12696 KB Output is correct
12 Correct 45 ms 8232 KB Output is correct
13 Correct 60 ms 9924 KB Output is correct
14 Correct 72 ms 12800 KB Output is correct
15 Correct 70 ms 12716 KB Output is correct
16 Correct 44 ms 12748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 84 ms 12696 KB Output is correct
12 Correct 45 ms 8232 KB Output is correct
13 Correct 60 ms 9924 KB Output is correct
14 Correct 72 ms 12800 KB Output is correct
15 Correct 70 ms 12716 KB Output is correct
16 Correct 44 ms 12748 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 81 ms 13028 KB Output is correct
23 Correct 75 ms 12828 KB Output is correct
24 Correct 56 ms 8960 KB Output is correct
25 Correct 80 ms 13004 KB Output is correct
26 Correct 67 ms 12816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 84 ms 12696 KB Output is correct
12 Correct 45 ms 8232 KB Output is correct
13 Correct 60 ms 9924 KB Output is correct
14 Correct 72 ms 12800 KB Output is correct
15 Correct 70 ms 12716 KB Output is correct
16 Correct 44 ms 12748 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 81 ms 13028 KB Output is correct
23 Correct 75 ms 12828 KB Output is correct
24 Correct 56 ms 8960 KB Output is correct
25 Correct 80 ms 13004 KB Output is correct
26 Correct 67 ms 12816 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 872 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 77 ms 13404 KB Output is correct
35 Correct 74 ms 13268 KB Output is correct
36 Correct 93 ms 13452 KB Output is correct
37 Correct 85 ms 13484 KB Output is correct
38 Correct 85 ms 13368 KB Output is correct
39 Correct 33 ms 7948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 84 ms 12696 KB Output is correct
12 Correct 45 ms 8232 KB Output is correct
13 Correct 60 ms 9924 KB Output is correct
14 Correct 72 ms 12800 KB Output is correct
15 Correct 70 ms 12716 KB Output is correct
16 Correct 44 ms 12748 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 1 ms 620 KB Output is correct
22 Correct 81 ms 13028 KB Output is correct
23 Correct 75 ms 12828 KB Output is correct
24 Correct 56 ms 8960 KB Output is correct
25 Correct 80 ms 13004 KB Output is correct
26 Correct 67 ms 12816 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 872 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 77 ms 13404 KB Output is correct
35 Correct 74 ms 13268 KB Output is correct
36 Correct 93 ms 13452 KB Output is correct
37 Correct 85 ms 13484 KB Output is correct
38 Correct 85 ms 13368 KB Output is correct
39 Correct 33 ms 7948 KB Output is correct
40 Correct 2 ms 812 KB Output is correct
41 Correct 3 ms 872 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 3 ms 852 KB Output is correct
44 Correct 93 ms 13904 KB Output is correct
45 Correct 104 ms 13884 KB Output is correct
46 Correct 94 ms 13844 KB Output is correct
47 Correct 93 ms 13872 KB Output is correct
48 Correct 77 ms 13820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 484 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 480 KB Output is correct
18 Correct 1 ms 476 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 476 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 3 ms 852 KB Output is correct
28 Correct 3 ms 872 KB Output is correct
29 Correct 3 ms 852 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 3 ms 852 KB Output is correct
32 Correct 3 ms 852 KB Output is correct
33 Correct 2 ms 852 KB Output is correct
34 Correct 3 ms 852 KB Output is correct
35 Correct 1 ms 480 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 3 ms 852 KB Output is correct
38 Correct 3 ms 852 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 0 ms 468 KB Output is correct
42 Correct 0 ms 468 KB Output is correct
43 Correct 0 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 0 ms 468 KB Output is correct
49 Correct 0 ms 468 KB Output is correct
50 Correct 84 ms 12696 KB Output is correct
51 Correct 45 ms 8232 KB Output is correct
52 Correct 60 ms 9924 KB Output is correct
53 Correct 72 ms 12800 KB Output is correct
54 Correct 70 ms 12716 KB Output is correct
55 Correct 44 ms 12748 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 0 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 4 ms 480 KB Output is correct
60 Correct 1 ms 620 KB Output is correct
61 Correct 81 ms 13028 KB Output is correct
62 Correct 75 ms 12828 KB Output is correct
63 Correct 56 ms 8960 KB Output is correct
64 Correct 80 ms 13004 KB Output is correct
65 Correct 67 ms 12816 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 2 ms 872 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 596 KB Output is correct
73 Correct 77 ms 13404 KB Output is correct
74 Correct 74 ms 13268 KB Output is correct
75 Correct 93 ms 13452 KB Output is correct
76 Correct 85 ms 13484 KB Output is correct
77 Correct 85 ms 13368 KB Output is correct
78 Correct 33 ms 7948 KB Output is correct
79 Correct 2 ms 812 KB Output is correct
80 Correct 3 ms 872 KB Output is correct
81 Correct 2 ms 852 KB Output is correct
82 Correct 3 ms 852 KB Output is correct
83 Correct 93 ms 13904 KB Output is correct
84 Correct 104 ms 13884 KB Output is correct
85 Correct 94 ms 13844 KB Output is correct
86 Correct 93 ms 13872 KB Output is correct
87 Correct 77 ms 13820 KB Output is correct
88 Correct 86 ms 15428 KB Output is correct
89 Correct 117 ms 15404 KB Output is correct
90 Correct 90 ms 15388 KB Output is correct
91 Correct 98 ms 15476 KB Output is correct
92 Correct 91 ms 14204 KB Output is correct
93 Correct 91 ms 14580 KB Output is correct
94 Correct 87 ms 14288 KB Output is correct
95 Correct 88 ms 15332 KB Output is correct
96 Correct 91 ms 15412 KB Output is correct
97 Correct 74 ms 15664 KB Output is correct
98 Correct 55 ms 14224 KB Output is correct
99 Correct 96 ms 14336 KB Output is correct