Submission #697839

#TimeUsernameProblemLanguageResultExecution timeMemory
697839blackscreen1Team Contest (JOI22_team)C++17
100 / 100
102 ms14924 KiB
#include <bits//stdc++.h>
using namespace std;
#define ll long long
#define st short
#define iloop(m, h) for (auto i = m; i != h; i+=(m<h?1:-1))
#define jloop(m, h) for (auto j = m; j != h; j+=(m<h?1:-1))
#define kloop(m, h) for (auto k = m; k != h; k+=(m<h?1:-1))
#define lloop(m, h) for (auto l = m; l != h; l+=(m<h?1:-1))
#define iloop_(m, h, g) for (auto i = m; i != h; i+=g)
#define jloop_(m, h, g) for (auto j = m; j != h; j+=g)
#define kloop_(m, h, g) for (auto k = m; k != h; k+=g)
#define lloop_(m, h, g) for (auto l = m; l != h; l+=g)
#define getchar_unlocked _getchar_nolock // comment before submission
#define pll pair<ll,ll>
#define plll pair<ll, pll>
#define pllll pair<pll, pll>
#define vll vector<ll>
#define qll queue<ll>
#define dll deque<ll>
#define pqll priority_queue<ll>
#define gll greater<ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll ax[n], ay[n], az[n];
    pll x[n], y[n], z[n];
    bool there[n];
    iloop(0, n) {
		there[i] = 1;
		cin >> ax[i] >> ay[i] >> az[i];
		x[i].first = ax[i], y[i].first = ay[i], z[i].first = az[i];
		x[i].second = y[i].second = z[i].second = i;
	}
	sort(x, x+n);
	sort(y, y+n);
	sort(z, z+n);
	ll cnt1 = n-1, cnt2 = n-1, cnt3 = n-1;
	while (cnt1 >= 0) {
		while (cnt1 >= 0 && there[x[cnt1].second] == 0) cnt1--;
		while (cnt2 >= 0 && there[y[cnt2].second] == 0) cnt2--;
		while (cnt3 >= 0 && there[z[cnt3].second] == 0) cnt3--;
		if (cnt1 == -1) break;
		if (ay[x[cnt1].second] == y[cnt2].first || az[x[cnt1].second] == z[cnt3].first) {there[x[cnt1].second] = 0; continue;}
		if (az[y[cnt2].second] == z[cnt3].first || ax[y[cnt2].second] == x[cnt1].first) {there[y[cnt2].second] = 0; continue;}
		if (ax[z[cnt3].second] == x[cnt1].first || ay[z[cnt3].second] == y[cnt2].first) {there[z[cnt3].second] = 0; continue;}
		break;
	}
	if (cnt1 == -1) {cout << -1; return 0;}
	else cout << x[cnt1].first + y[cnt2].first + z[cnt3].first;
}
#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...