Submission #1244289

#TimeUsernameProblemLanguageResultExecution timeMemory
1244289lovrotTeam Contest (JOI22_team)C++20
100 / 100
75 ms4448 KiB
#define db(...) fprintf(stderr, __VA_ARGS__) #include <cstdio> #include <algorithm> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int N = 1.5e5 + 10; int X[N], Y[N], Z[N]; int xi[N], yi[N], zi[N]; int bio[N]; int compatible(int a, int b, int c) { int A = 0, B = 0, C = 0; if(X[a] >= X[b] && X[a] >= X[c]) A ++; if(Y[a] >= Y[b] && Y[a] >= Y[c]) A ++; if(Z[a] >= Z[b] && Z[a] >= Z[c]) A ++; if(X[b] >= X[a] && X[b] >= X[c]) B ++; if(Y[b] >= Y[a] && Y[b] >= Y[c]) B ++; if(Z[b] >= Z[a] && Z[b] >= Z[c]) B ++; if(X[c] >= X[b] && X[c] >= X[a]) C ++; if(Y[c] >= Y[b] && Y[c] >= Y[a]) C ++; if(Z[c] >= Z[b] && Z[c] >= Z[a]) C ++; if(A == 1 && B == 1 && C == 1) { return -1; } return A >= 2 ? a : (B >= 2 ? b : c); } int main() { int n; scanf("%d", &n); for(int i = 0; i < n; ++i) { scanf("%d%d%d", X + i, Y + i, Z + i); xi[i] = yi[i] = zi[i] = i; } sort(xi, xi + n, [](int a, int b) { return X[a] > X[b] || (X[a] == X[b] && a < b); }); sort(yi, yi + n, [](int a, int b) { return Y[a] > Y[b] || (Y[a] == Y[b] && a < b); }); sort(zi, zi + n, [](int a, int b) { return Z[a] > Z[b] || (Z[a] == Z[b] && a < b); }); // for(int i = 0; i < n; ++i) { db("%d%c", xi[i], " \n"[i == n - 1]); } // for(int i = 0; i < n; ++i) { db("%d%c", yi[i], " \n"[i == n - 1]); } // for(int i = 0; i < n; ++i) { db("%d%c", zi[i], " \n"[i == n - 1]); } for(int i = 0, j = 0, k = 0; i < n && j < n && k < n; ) { if(i < n && bio[xi[i]]) { i ++; continue; } if(j < n && bio[yi[j]]) { j ++; continue; } if(k < n && bio[zi[k]]) { k ++; continue; } int res = compatible(xi[i], yi[j], zi[k]); // printf("%d %d %d\n", xi[i], yi[j], zi[k]); if(res == -1) { printf("%d\n", X[xi[i]] + Y[yi[j]] + Z[zi[k]]); return 0; } bio[res] = 1; if(xi[i] == res) { i ++; } if(yi[j] == res) { j ++; } if(zi[k] == res) { k ++; } } printf("-1\n"); return 0; }

Compilation message (stderr)

team.cpp: In function 'int main()':
team.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
team.cpp:40:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |                 scanf("%d%d%d", X + i, Y + i, Z + i);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...