답안 #768716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768716 2023-06-28T13:52:55 Z NintsiChkhaidze Team Contest (JOI22_team) C++17
37 / 100
2000 ms 45276 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define s second
#define f first
#define left (node<<1),l,((l+r)>>1)
#define right ((node<<1)|1),((l+r)>>1) + 1,r
// #define int ll 
using namespace std;

const int N = 150000 + 5;

bool f[N],fix[N];
int x[N],y[N],z[N],cnt[N],mx[6];
int d[3*N],rev[3*N];
map <int,int> mp;
multiset <int> st[5];
vector <int> v[5][N];

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
	
	int n;
	cin>>n;
	
	int id=0;
	for (int i = 1; i <= n; i++){
		cin>>x[i]>>y[i]>>z[i];
		d[++id] = x[i];
		d[++id] = y[i];
		d[++id] = z[i];
		
	}
	sort(d+1,d+id+1);
	int val=0;
	for (int i = 1; i <= id; i++){
		if (i == 1 || d[i] != d[i - 1]) ++val;	
		mp[d[i]] = val;
		rev[val] = d[i];
	}
	
	for (int i = 1; i <= n; i++){
		x[i] = mp[x[i]];
		y[i] = mp[y[i]];
		z[i] = mp[z[i]];
		mx[1] = max(mx[1],x[i]);
		mx[2] = max(mx[2],y[i]);
		mx[3] = max(mx[3],z[i]);	
	}
	
	queue <int> q;
	for (int i = 1; i <= n; i++){
		if (x[i] == mx[1]) ++cnt[i];
		if (y[i] == mx[2]) ++cnt[i];
		if (z[i] == mx[3]) ++cnt[i];
		if (cnt[i] > 1) {
			q.push(i),fix[i]=1;	
		}
		
		v[1][x[i]].pb(i);
		v[2][y[i]].pb(i);
		v[3][z[i]].pb(i);
		st[1].insert(x[i]);
		st[2].insert(y[i]);
		st[3].insert(z[i]);
	}
	
	while (q.size()){
		int idx = q.front();
		q.pop();
		if (f[idx]) continue;
		
		f[idx] = 1;
		st[1].erase(st[1].find(x[idx]));
		st[2].erase(st[2].find(y[idx]));
		st[3].erase(st[3].find(z[idx]));
		
		if(st[1].size() == 0){
			cout<<-1;
			exit(0);
		}
		mx[1] = *st[1].rbegin();
		mx[2] = *st[2].rbegin();
		mx[3] = *st[3].rbegin();
		
		for (int j = 1; j <= 3; j++){
			for (int p: v[j][mx[j]]){
				if (!fix[p]){
					cnt[p] = 0;
					if (x[p] == mx[1]) ++cnt[p];
					if (y[p] == mx[2]) ++cnt[p];
					if (z[p] == mx[3]) ++cnt[p];
					if (cnt[p] >= 2) {
						fix[p] = 1;
						q.push(p);
					}
				}
			}
		}
	}
	
	cout<<rev[mx[1]] + rev[mx[2]] + rev[mx[3]];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17876 KB Output is correct
2 Correct 8 ms 17876 KB Output is correct
3 Correct 8 ms 17884 KB Output is correct
4 Correct 9 ms 17876 KB Output is correct
5 Correct 7 ms 17876 KB Output is correct
6 Correct 8 ms 17980 KB Output is correct
7 Correct 7 ms 17916 KB Output is correct
8 Correct 8 ms 17876 KB Output is correct
9 Correct 8 ms 17876 KB Output is correct
10 Correct 8 ms 17876 KB Output is correct
11 Correct 8 ms 17876 KB Output is correct
12 Correct 7 ms 17876 KB Output is correct
13 Correct 8 ms 17856 KB Output is correct
14 Correct 9 ms 18004 KB Output is correct
15 Correct 8 ms 18004 KB Output is correct
16 Correct 8 ms 18004 KB Output is correct
17 Correct 8 ms 18004 KB Output is correct
18 Correct 9 ms 18004 KB Output is correct
19 Correct 9 ms 18004 KB Output is correct
20 Correct 9 ms 17948 KB Output is correct
21 Correct 10 ms 18004 KB Output is correct
22 Correct 8 ms 18096 KB Output is correct
23 Correct 8 ms 18020 KB Output is correct
24 Correct 8 ms 18004 KB Output is correct
25 Correct 8 ms 18004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17876 KB Output is correct
2 Correct 8 ms 17876 KB Output is correct
3 Correct 8 ms 17884 KB Output is correct
4 Correct 9 ms 17876 KB Output is correct
5 Correct 7 ms 17876 KB Output is correct
6 Correct 8 ms 17980 KB Output is correct
7 Correct 7 ms 17916 KB Output is correct
8 Correct 8 ms 17876 KB Output is correct
9 Correct 8 ms 17876 KB Output is correct
10 Correct 8 ms 17876 KB Output is correct
11 Correct 8 ms 17876 KB Output is correct
12 Correct 7 ms 17876 KB Output is correct
13 Correct 8 ms 17856 KB Output is correct
14 Correct 9 ms 18004 KB Output is correct
15 Correct 8 ms 18004 KB Output is correct
16 Correct 8 ms 18004 KB Output is correct
17 Correct 8 ms 18004 KB Output is correct
18 Correct 9 ms 18004 KB Output is correct
19 Correct 9 ms 18004 KB Output is correct
20 Correct 9 ms 17948 KB Output is correct
21 Correct 10 ms 18004 KB Output is correct
22 Correct 8 ms 18096 KB Output is correct
23 Correct 8 ms 18020 KB Output is correct
24 Correct 8 ms 18004 KB Output is correct
25 Correct 8 ms 18004 KB Output is correct
26 Correct 15 ms 19540 KB Output is correct
27 Correct 14 ms 19172 KB Output is correct
28 Correct 16 ms 19204 KB Output is correct
29 Correct 14 ms 18988 KB Output is correct
30 Correct 11 ms 18704 KB Output is correct
31 Correct 13 ms 18772 KB Output is correct
32 Correct 14 ms 18764 KB Output is correct
33 Correct 34 ms 18924 KB Output is correct
34 Correct 16 ms 19632 KB Output is correct
35 Correct 9 ms 18132 KB Output is correct
36 Correct 12 ms 18100 KB Output is correct
37 Correct 12 ms 18772 KB Output is correct
38 Correct 13 ms 18780 KB Output is correct
39 Correct 9 ms 18260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17892 KB Output is correct
2 Correct 9 ms 17876 KB Output is correct
3 Correct 9 ms 17852 KB Output is correct
4 Correct 8 ms 17908 KB Output is correct
5 Correct 8 ms 17876 KB Output is correct
6 Correct 8 ms 17976 KB Output is correct
7 Correct 9 ms 17876 KB Output is correct
8 Correct 8 ms 17876 KB Output is correct
9 Correct 8 ms 17876 KB Output is correct
10 Correct 9 ms 17876 KB Output is correct
11 Execution timed out 2066 ms 45276 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17892 KB Output is correct
2 Correct 9 ms 17876 KB Output is correct
3 Correct 9 ms 17852 KB Output is correct
4 Correct 8 ms 17908 KB Output is correct
5 Correct 8 ms 17876 KB Output is correct
6 Correct 8 ms 17976 KB Output is correct
7 Correct 9 ms 17876 KB Output is correct
8 Correct 8 ms 17876 KB Output is correct
9 Correct 8 ms 17876 KB Output is correct
10 Correct 9 ms 17876 KB Output is correct
11 Execution timed out 2066 ms 45276 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17892 KB Output is correct
2 Correct 9 ms 17876 KB Output is correct
3 Correct 9 ms 17852 KB Output is correct
4 Correct 8 ms 17908 KB Output is correct
5 Correct 8 ms 17876 KB Output is correct
6 Correct 8 ms 17976 KB Output is correct
7 Correct 9 ms 17876 KB Output is correct
8 Correct 8 ms 17876 KB Output is correct
9 Correct 8 ms 17876 KB Output is correct
10 Correct 9 ms 17876 KB Output is correct
11 Execution timed out 2066 ms 45276 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17892 KB Output is correct
2 Correct 9 ms 17876 KB Output is correct
3 Correct 9 ms 17852 KB Output is correct
4 Correct 8 ms 17908 KB Output is correct
5 Correct 8 ms 17876 KB Output is correct
6 Correct 8 ms 17976 KB Output is correct
7 Correct 9 ms 17876 KB Output is correct
8 Correct 8 ms 17876 KB Output is correct
9 Correct 8 ms 17876 KB Output is correct
10 Correct 9 ms 17876 KB Output is correct
11 Execution timed out 2066 ms 45276 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 17876 KB Output is correct
2 Correct 8 ms 17876 KB Output is correct
3 Correct 8 ms 17884 KB Output is correct
4 Correct 9 ms 17876 KB Output is correct
5 Correct 7 ms 17876 KB Output is correct
6 Correct 8 ms 17980 KB Output is correct
7 Correct 7 ms 17916 KB Output is correct
8 Correct 8 ms 17876 KB Output is correct
9 Correct 8 ms 17876 KB Output is correct
10 Correct 8 ms 17876 KB Output is correct
11 Correct 8 ms 17876 KB Output is correct
12 Correct 7 ms 17876 KB Output is correct
13 Correct 8 ms 17856 KB Output is correct
14 Correct 9 ms 18004 KB Output is correct
15 Correct 8 ms 18004 KB Output is correct
16 Correct 8 ms 18004 KB Output is correct
17 Correct 8 ms 18004 KB Output is correct
18 Correct 9 ms 18004 KB Output is correct
19 Correct 9 ms 18004 KB Output is correct
20 Correct 9 ms 17948 KB Output is correct
21 Correct 10 ms 18004 KB Output is correct
22 Correct 8 ms 18096 KB Output is correct
23 Correct 8 ms 18020 KB Output is correct
24 Correct 8 ms 18004 KB Output is correct
25 Correct 8 ms 18004 KB Output is correct
26 Correct 15 ms 19540 KB Output is correct
27 Correct 14 ms 19172 KB Output is correct
28 Correct 16 ms 19204 KB Output is correct
29 Correct 14 ms 18988 KB Output is correct
30 Correct 11 ms 18704 KB Output is correct
31 Correct 13 ms 18772 KB Output is correct
32 Correct 14 ms 18764 KB Output is correct
33 Correct 34 ms 18924 KB Output is correct
34 Correct 16 ms 19632 KB Output is correct
35 Correct 9 ms 18132 KB Output is correct
36 Correct 12 ms 18100 KB Output is correct
37 Correct 12 ms 18772 KB Output is correct
38 Correct 13 ms 18780 KB Output is correct
39 Correct 9 ms 18260 KB Output is correct
40 Correct 9 ms 17892 KB Output is correct
41 Correct 9 ms 17876 KB Output is correct
42 Correct 9 ms 17852 KB Output is correct
43 Correct 8 ms 17908 KB Output is correct
44 Correct 8 ms 17876 KB Output is correct
45 Correct 8 ms 17976 KB Output is correct
46 Correct 9 ms 17876 KB Output is correct
47 Correct 8 ms 17876 KB Output is correct
48 Correct 8 ms 17876 KB Output is correct
49 Correct 9 ms 17876 KB Output is correct
50 Execution timed out 2066 ms 45276 KB Time limit exceeded
51 Halted 0 ms 0 KB -