Submission #620024

#TimeUsernameProblemLanguageResultExecution timeMemory
620024CSQ31Team Contest (JOI22_team)C++17
100 / 100
208 ms7860 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) #define all(a) a.begin(),a.end() #define owo ios_base::sync_with_stdio(0);cin.tie(0); typedef pair<int,int> pii; typedef long long int ll; const int MAXN = 5e5; int a[MAXN],b[MAXN],c[MAXN]; bool del[MAXN]; int main() { int n; cin>>n; for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i]; vector<int>pa(n),pb(n),pc(n); for(int i=0;i<n;i++){ pa[i] = pb[i] = pc[i] = i; } sort(all(pa),[&](int i,int j){return a[j] > a[i];}); sort(all(pb),[&](int i,int j){return b[j] > b[i];}); sort(all(pc),[&](int i,int j){return c[j] > c[i];}); int ta,tb,tc; ta = tb = tc = n-1; while(ta>=0 && tb>=0 && tc>=0){ int cnta = 0,cntb = 0,cntc = 0; if(b[pa[ta]] == b[pb[tb]])cnta++; if(c[pa[ta]] == c[pc[tc]])cnta++; if(a[pb[tb]] == a[pa[ta]])cntb++; if(c[pb[tb]] == c[pc[tc]])cntb++; if(a[pc[tc]] == a[pa[ta]])cntc++; if(b[pc[tc]] == b[pb[tb]])cntc++; //cout<<ta<<" "<<tb<<" "<<tc<<'\n'; if(cnta>=1){ del[pa[ta]] = 1; ta--; } else if(cntb>=1){ del[pb[tb]] = 1; tb--; } else if(cntc>=1){ del[pc[tc]] = 1; tc--; } else{ cout<<a[pa[ta]] + b[pb[tb]] + c[pc[tc]]<<'\n'; return 0; } while(ta != -1 && del[pa[ta]])ta--; while(tb != -1 && del[pb[tb]])tb--; while(tc != -1 && del[pc[tc]])tc--; } cout<<-1; }
#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...