Submission #768400

#TimeUsernameProblemLanguageResultExecution timeMemory
768400nguyentunglamTeam Contest (JOI22_team)C++17
100 / 100
481 ms62876 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 2e5 + 10; int x[N], y[N], z[N]; map<pair<int, int>, vector<int> > m[3]; bool ban[N]; int X, Y, Z; vector<ii> vx, vy, vz; int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> x[i] >> y[i] >> z[i]; vx.emplace_back(x[i], i); vy.emplace_back(y[i], i); vz.emplace_back(z[i], i); m[0][{x[i], y[i]}].push_back(i); m[1][{y[i], z[i]}].push_back(i); m[2][{x[i], z[i]}].push_back(i); } sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end()); sort(vz.begin(), vz.end()); int cur = n; while (cur >= 3) { while (ban[vx.back().se]) vx.pop_back(); while (ban[vy.back().se]) vy.pop_back(); while (ban[vz.back().se]) vz.pop_back(); if (vx.empty() || vy.empty() || vz.empty()) break; X = vx.back().first; Y = vy.back().first; Z = vz.back().first; int pre = cur; for(int &j : m[0][{X, Y}]) if (ban[j] == 0) { cur--; ban[j] = 1; } for(int &j : m[1][{Y, Z}]) if (ban[j] == 0) { cur--; ban[j] = 1; } for(int &j : m[2][{X, Z}]) if (ban[j] == 0) { cur--; ban[j] = 1; } m[0][{X, Y}].clear(); m[1][{Y, Z}].clear(); m[2][{X, Z}].clear(); if (pre == cur) return cout << X + Y + Z, 0; } cout << -1; }

Compilation message (stderr)

team.cpp: In function 'int main()':
team.cpp:17:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:21:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
team.cpp:22:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...