Submission #1132841

#TimeUsernameProblemLanguageResultExecution timeMemory
1132841cleptopodTeam Contest (JOI22_team)C++20
100 / 100
64 ms3912 KiB
/**
 *    author: david goggins
 *    created:
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n), z(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  vector<int> ord_x(n), ord_y(n), ord_z(n);
  iota(ord_x.begin(), ord_x.end(), 0);
  iota(ord_y.begin(), ord_y.end(), 0);
  iota(ord_z.begin(), ord_z.end(), 0);
  sort(ord_x.begin(), ord_x.end(), [&](int i, int j) {
    return (x[i] < x[j]);
  });
  sort(ord_y.begin(), ord_y.end(), [&](int i, int j) {
    return (y[i] < y[j]);
  });
  sort(ord_z.begin(), ord_z.end(), [&](int i, int j) {
    return (z[i] < z[j]);
  });
  vector<bool> vis(n);
  int px = n - 1, py = n - 1, pz = n - 1;
  while (px >= 0 && py >= 0 && pz >= 0) {
    int vx = x[ord_x[px]], vy = y[ord_y[py]], vz = z[ord_z[pz]];
    bool bad = false;
    if (y[ord_x[px]] >= vy || z[ord_x[px]] >= vz) {
      bad = true;
      vis[ord_x[px]] = true;
      px--;
    } else if (x[ord_y[py]] >= vx || z[ord_y[py]] >= vz) {
      bad = true;
      vis[ord_y[py]] = true;
      py--;
    } else if (x[ord_z[pz]] >= vx || y[ord_z[pz]] >= vy) {
      bad = true;
      vis[ord_z[pz]] = true;
      pz--;
    }
    if (!bad) {
      cout << vx + vy + vz << '\n';
      return 0;
    }
    while (px >= 0 && vis[ord_x[px]]) {
      px--;
    }
    while (py >= 0 && vis[ord_y[py]]) {
      py--;
    }
    while (pz >= 0 && vis[ord_z[pz]]) {
      pz--;
    }
  }
  cout << -1 << '\n';
  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...