Submission #696095

#TimeUsernameProblemLanguageResultExecution timeMemory
696095pavementTeam Contest (JOI22_team)C++17
100 / 100
140 ms15400 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, ans, X[150005], Y[150005], Z[150005];
bool invalid[150005];
priority_queue<ii> pqX, pqY, pqZ;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++){
		cin >> X[i] >> Y[i] >> Z[i];
		pqX.emplace(X[i], i);
		pqY.emplace(Y[i], i);
		pqZ.emplace(Z[i], i);
	}
	while (1) {
		while (!pqX.empty() && invalid[pqX.top().second]) pqX.pop();
		while (!pqY.empty() && invalid[pqY.top().second]) pqY.pop();
		while (!pqZ.empty() && invalid[pqZ.top().second]) pqZ.pop();
		if (pqX.empty() || pqY.empty() || pqZ.empty()) {
			ans = -1;
			break;
		}
		auto x = pqX.top(), y = pqY.top(), z = pqZ.top();
		bool bad = 0;
		for (auto i : {x.second, y.second, z.second}) {
			int cnt = 0;
			if (X[i] == x.first) cnt++;
			if (Y[i] == y.first) cnt++;
			if (Z[i] == z.first) cnt++;
			assert(cnt > 0);
			if (cnt > 1) {
				invalid[i] = 1;
				bad = 1;
			}
		}
		if (!bad) {
			ans = x.first + y.first + z.first;
			break;
		}
	}
	cout << ans << '\n';
}

Compilation message (stderr)

team.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main() {
      | ^~~~
#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...