Submission #1058901

#TimeUsernameProblemLanguageResultExecution timeMemory
1058901TrinhKhanhDungTeam Contest (JOI22_team)C++14
100 / 100
78 ms9924 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(998244353) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} const int MAX = 15e4 + 10; int N; int x[MAX], y[MAX], z[MAX]; bool ok[MAX]; vector<pair<int, int>> v1, v2, v3; void solve(){ cin >> N; for(int i=1; i<=N; i++){ cin >> x[i] >> y[i] >> z[i]; v1.push_back(make_pair(x[i], i)); v2.push_back(make_pair(y[i], i)); v3.push_back(make_pair(z[i], i)); } sort(ALL(v1)); sort(ALL(v2)); sort(ALL(v3)); while(sz(v1) && sz(v2) && sz(v3)){ vector<int> ord; ord.push_back(v1.back().se); ord.push_back(v2.back().se); ord.push_back(v3.back().se); bool check = true; for(int k: ord){ int d = 0; if(v1.back().fi == x[k]) d++; if(v2.back().fi == y[k]) d++; if(v3.back().fi == z[k]) d++; if(d > 1) ok[k] = true; } if(ok[v1.back().se]){ v1.pop_back(); check = false; } if(ok[v2.back().se]){ v2.pop_back(); check = false; } if(ok[v3.back().se]){ v3.pop_back(); check = false; } if(check){ cout << 1LL * v1.back().fi + v2.back().fi + v3.back().fi << '\n'; return; } } cout << "-1\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("minimum.inp", "r", stdin); // freopen("minimum.out", "w", stdout); int t = 1; while(t--){ solve(); } 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...