이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
struct beaver
{
int x, y, z, idx;
beaver(int _x = 0, int _y = 0, int _z = 0, int _idx = 0)
{
x = _x;
y = _y;
z = _z;
idx = _idx;
}
};
const int maxn = 150010;
beaver bx[maxn], by[maxn], bz[maxn];
bool cmp_x(beaver b1, beaver b2)
{
return b1.x < b2.x;
}
bool cmp_y(beaver b1, beaver b2)
{
return b1.y < b2.y;
}
bool cmp_z(beaver b1, beaver b2)
{
return b1.z < b2.z;
}
int n, used[maxn];
void solve()
{
cin >> n;
for (int i = 1; i <= n; i ++)
{
beaver b;
cin >> b.x >> b.y >> b.z;
b.idx = i;
bx[i] = by[i] = bz[i] = b;
}
sort(bx + 1, bx + n + 1, cmp_x);
sort(by + 1, by + n + 1, cmp_y);
sort(bz + 1, bz + n + 1, cmp_z);
int px, py, pz;
px = n;
py = n;
pz = n;
for (int i = 1; i <= n; i ++)
{
while(used[bx[px].idx] == 1)
px --;
while(used[by[py].idx] == 1)
py --;
while(used[bz[pz].idx] == 1)
pz --;
int mx = bx[px].x;
int my = by[py].y;
int mz = bz[pz].z;
if (bx[px].y == my || bx[px].z == mz)
{
used[bx[px].idx] = 1;
continue;
}
if (by[py].x == mx || by[py].z == mz)
{
used[by[py].idx] = 1;
continue;
}
if (bz[pz].x == mx || bz[pz].y == my)
{
used[bz[pz].idx] = 1;
continue;
}
cout << mx + my + mz << endl;
return;
}
cout << -1 << endl;
}
int main()
{
solve();
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... |