제출 #586146

#제출 시각아이디문제언어결과실행 시간메모리
586146notaTeam Contest (JOI22_team)C++14
0 / 100
0 ms340 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define fi first #define se second #define pii pair<int, int> using namespace std; const int maxN = 150001; int n; pii x[maxN], y[maxN], z[maxN]; void Input() { cin >> n; for(int i = 1; i <= n; i++) { cin >> x[i].fi >> y[i].fi >> z[i].fi; x[i].se = y[i].se = z[i].se = i; } } bool flag[maxN]; void Solve() { fill(flag + 1, flag + 1 + n, false); sort(x+1, x+1+n); sort(y+1, y+1+n); sort(z+1, z+1+n); int resx = n, resy = n, resz = n; while(resx != 0 && resy != 0 && resz != 0) { int tmpx = x[resx].fi, tmpy = y[resy].fi, tmpz = z[resz].fi; int xx = (y[x[resx].se].fi == tmpy) + (z[x[resx].se].fi == tmpz); int yy = (x[y[resy].se].fi == tmpx) + (z[y[resy].se].fi == tmpz); int zz = (x[z[resz].se].fi == tmpx) + (y[z[resz].se].fi == tmpy); if(xx == 0 && yy == 0 && zz == 0) { cout << tmpx + tmpy + tmpz; return; } if(xx > 0) { flag[x[resx].se] = true; resx--; goto hi; } if(yy > 0) { flag[y[resy].se] = true; resy--; goto hi; } if(zz > 0) { flag[z[resz].se] = true; resz--; goto hi; } hi: while(flag[x[resx].se] && resx != 0) resx--; while(flag[y[resy].se] && resy != 0) resy--; while(flag[z[resz].se] && resz != 0) resz--; } cout << -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Input(); Solve(); }
#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...