제출 #1212778

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

#define int long long

const int MAXN = 101;
const int mod = 998244353;

struct Node
{
    int x, y, z;
    Node(int x, int y, int z) : x(x), y(y), z(z) {};
    Node() = default;

    int get_max()
    {
        return std::max(x, std::max(y, z));
    }
};

signed
main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    std::cin >> n;

    std::vector<Node> all(n);
    std::multiset<int> x, y, z;

    Node max = Node(0, 0, 0);
    for (int i = 0; i < n; i++)
    {
        std::cin >> all[i].x >> all[i].y >> all[i].z;
        x.insert(all[i].x);
        y.insert(all[i].y);
        z.insert(all[i].z);
    }

    std::map<std::pair<int, int>, std::vector<int>> nowxy, nowyz, nowxz;
    std::vector<bool> used(n, false);
    for (int i = 0; i < n; i++)
    {
        nowxy[std::make_pair(all[i].x, all[i].y)].push_back(i);
        nowyz[std::make_pair(all[i].y, all[i].z)].push_back(i);
        nowxz[std::make_pair(all[i].x, all[i].z)].push_back(i);
    }
    bool was = false;

    max.x = *(--x.end());
    max.y = *(--y.end());
    max.z = *(--z.end());
    do
    {
        was = false;
        for (auto v : nowxy[std::make_pair(max.x, max.y)])
        {
            was = true;
            if (!used[v])
            {
                x.erase(x.find(all[v].x));
                z.erase(z.find(all[v].z));
                y.erase(y.find(all[v].y));
            }
            used[v] = true;
            // std::cout << v << ' ';
        }
        nowxy[std::make_pair(max.x, max.y)].clear();

        for (auto v : nowxz[std::make_pair(max.x, max.z)])
        {
            was = true;
            if (!used[v])
            {
                x.erase(x.find(all[v].x));
                z.erase(z.find(all[v].z));
                y.erase(y.find(all[v].y));
            }
            used[v] = true;
            // std::cout << v << ' ';
        }
        nowxz[std::make_pair(max.x, max.z)].clear();

        for (auto v : nowyz[std::make_pair(max.y, max.z)])
        {
            was = true;
            if (!used[v])
            {
                x.erase(x.find(all[v].x));
                z.erase(z.find(all[v].z));
                y.erase(y.find(all[v].y));
            }
            used[v] = true;
            // std::cout << v << ' ';
        }
        // std::cout << std::endl;
        nowyz[std::make_pair(max.y, max.z)].clear();

        if (x.size() == 0)
        {
            std::cout << -1;
            return 0;
        }

        // std::cout << max.x << ' ' << max.y << ' ' << max.z << ' ' << was << std::endl;

        max.x = *(--x.end());
        max.y = *(--y.end());
        max.z = *(--z.end());
    } while (was);

    std::cout << max.x + max.y + max.z;
}
#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...