제출 #1338057

#제출 시각아이디문제언어결과실행 시간메모리
1338057MisterReaperTeam Contest (JOI22_team)C++20
100 / 100
73 ms4504 KiB
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG
    #include "debug.h"
#else
    #define debug(...) void(23)
#endif

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N;
    std::cin >> N;
    std::vector<std::array<int, 3>> A(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i][0] >> A[i][1] >> A[i][2];
    }

    std::vector<int> vx(N), vy(N), vz(N);
    std::iota(vx.begin(), vx.end(), 0);
    std::sort(vx.begin(), vx.end(), [&](auto lhs, auto rhs) -> int {
        return A[lhs][0] > A[rhs][0];
    });
    std::iota(vy.begin(), vy.end(), 0);
    std::sort(vy.begin(), vy.end(), [&](auto lhs, auto rhs) -> int {
        return A[lhs][1] > A[rhs][1];
    });
    std::iota(vz.begin(), vz.end(), 0);
    std::sort(vz.begin(), vz.end(), [&](auto lhs, auto rhs) -> int {
        return A[lhs][2] > A[rhs][2];
    });

    std::vector<int> act(N, true);

    int ans = -1;
    int p0 = 0;
    int p1 = 0;
    int p2 = 0;
    while (p0 < N && p1 < N && p2 < N) {
        int a = vx[p0];
        int b = vy[p1];
        int c = vz[p2];
        int cntx = (A[a][0] == A[a][0]) + (A[a][1] == A[b][1]) + (A[a][2] == A[c][2]);
        int cnty = (A[b][0] == A[a][0]) + (A[b][1] == A[b][1]) + (A[b][2] == A[c][2]);
        int cntz = (A[c][0] == A[a][0]) + (A[c][1] == A[b][1]) + (A[c][2] == A[c][2]);
        if (!act[a]) {
            p0++;
        } else if (!act[b]) {
            p1++;
        } else if (!act[c]) {
            p2++;
        } else {
            if (cntx > 1) {
                act[a] = false;
                p0++;
            } else if (cnty > 1) {
                act[b] = false;
                p1++;
            } else if (cntz > 1) {
                act[c] = false;
                p2++;
            } else {
                ans = A[a][0] + A[b][1] + A[c][2];
                break;
            }
        }
    }

    std::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...