제출 #641597

#제출 시각아이디문제언어결과실행 시간메모리
641597onlk97Team Contest (JOI22_team)C++14
100 / 100
230 ms10264 KiB
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+1][3];
	for (int i=1; i<=n; i++){
		for (int j=0; j<3; j++) cin>>a[i][j];
	}
	priority_queue <pair <int,int> > pq[3];
	for (int i=1; i<=n; i++){
		for (int j=0; j<3; j++) pq[j].push(make_pair(a[i][j],i));
	}
	bool removed[n+1];
	for (int i=1; i<=n; i++) removed[i]=0;
	for (;;){
		if (!pq[0].size()||!pq[1].size()||!pq[2].size()) break;
		bool ok=1;
		for (int j=0; j<3; j++){
			if (removed[pq[j].top().second]){
				pq[j].pop();
				ok=0;
				break;
			}
			for (int k=0; k<3; k++){
				if (j==k) continue;
				if (a[pq[j].top().second][k]==pq[k].top().first){
					removed[pq[j].top().second]=1;
					pq[j].pop();
					ok=0;
					break;
				}
			}
			if (!ok) break;
		}
		if (ok){
			cout<<pq[0].top().first+pq[1].top().first+pq[2].top().first<<'\n';
			return 0;
		}
	}
	cout<<"-1\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...