이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define all(a) a.begin(),a.end()
const int mxN = (int)1.5e5+10;
using ar = array<int,4>;
vector<ar> coder[3];
bool bad[mxN];
int n;
int32_t main() {
cin >> n;
for(int i = 0; i < n; i++){
int x,y,z; cin >>x>>y>>z;
for(int j = 0; j < 3; j++) coder[j].pb({x,y,z,i});
}
for(int j = 0; j < 3; j++)
sort(all(coder[j]),[&](ar a, ar b){ return a[j] < b[j]; });
int i[] = {n-1,n-1,n-1};
while(1){
for(int j = 0; j < 3; j++){
while(i[j]>=0 and bad[coder[j][i[j]][3]]) i[j]--;
if(i[j]<0){cout<<-1;return 0;}
}
vector<int> val; val.clear();
for(int j = 0; j < 3; j++) val.pb(coder[j][i[j]][j]);
for(int I = 0; I < 3; I++)
for(int j = 0; j < 3; j++)
if(I!=j and coder[I][i[I]][j]==val[j])
bad[coder[I][i[I]][3]]=1;
bool ok = 1;
for(int j = 0; j < 3; j++) ok&=!bad[coder[j][i[j]][3]];
if(ok){ cout << val[0]+val[1]+val[2]; return 0; }
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |