Submission #568021

#TimeUsernameProblemLanguageResultExecution timeMemory
568021maomao90Team Contest (JOI22_team)C++17
100 / 100
137 ms6284 KiB
#include <bits/stdc++.h> using namespace std; #define REP(i, j, k) for (int i = j; i < k; i++) #define RREP(i, j, k) for (int i = j; i >= k; i--) template <class T> bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;} template <class T> bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;} typedef long long ll; #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; typedef tuple<int, int, int> iii; #define ALL(x) x.begin(), x.end() #define SZ(x) (int) x.size() #define pb push_back typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vll; #ifndef DEBUG #define cerr if(0) cerr #endif const int MAXN = 150005; const int INF = 1000000005; const ll LINF = 1000000000000000005; int n; int g[MAXN][3]; vi id[3]; ll ans; bool used[MAXN]; int main() { #ifndef DEBUG ios::sync_with_stdio(0), cin.tie(0); #endif cin >> n; REP (i, 0, n) { REP (j, 0, 3) { cin >> g[i][j]; } } REP (i, 0, 3) { id[i] = vi(n, 0); iota(ALL(id[i]), 0); sort(ALL(id[i]), [&] (int l, int r) { return g[l][i] < g[r][i]; }); } ans = -1; while (1) { bool pos = 1; bool nopop = 1; REP (i, 0, 3) { while (!id[i].empty() && used[id[i].back()]) { id[i].pop_back(); } if (id[i].empty()) { pos = 0; break; } REP (j, 0, 3) { if (i == j) continue; while (!id[j].empty() && used[id[j].back()]) { id[j].pop_back(); } if (id[j].empty()) { pos = 0; break; } int u = id[i].back(), v = id[j].back(); while (g[u][i] == g[v][i]) { nopop = 0; id[j].pop_back(); used[v] = 1; if (id[j].empty()) { pos = 0; break; } v = id[j].back(); } if (!pos) { break; } } if (!pos) { break; } } if (nopop && pos) { ans = 0; REP (i, 0, 3) { ans += g[id[i].back()][i]; } } if (!pos || ans != -1) { break; } } cout << ans << '\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...