제출 #852113

#제출 시각아이디문제언어결과실행 시간메모리
852113ieeTeam Contest (JOI22_team)C++17
100 / 100
325 ms27416 KiB
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector<vector<int>> V(3, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> V[j][i];
		}
	}
	vector<set<pair<int, int>>> se(3);
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < n; j++) {
			se[i].emplace(V[i][j], j);
		}
	}
	while (!se[0].empty()) {
		vector<int> id, mx;
		for (int i = 0; i < 3; i++) {
			id.push_back(se[i].rbegin()->second);
			mx.push_back(se[i].rbegin()->first);
		}
		set<int> to_erase;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (j != i && mx[j] == V[j][id[i]]) {
					to_erase.insert(id[i]);
				}
			}
		}
		if (to_erase.empty()) {
			cout << accumulate(mx.begin(), mx.end(), 0) << "\n";
			return 0;
		}
		for (int i : to_erase) {
			for (int j = 0; j < 3; j++) {
				se[j].erase({V[j][i], i});
			}
		}
	}
	cout << -1 << "\n";
	return 0;
}
#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...