답안 #898392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898392 2024-01-04T15:33:12 Z lolismek Team Contest (JOI22_team) C++14
0 / 100
1 ms 604 KB
#include <algorithm>
#include <iostream>
#include <climits>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <iomanip>
#include <cassert>

#include <random>
#include <chrono>

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using ull = unsigned long long;
using ll = long long;

//#define int __int128
//#define int ll
#define pii pair <int, int>
#define all(a) (a).begin(), (a).end()
#define fr first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound

#define vt vector
#define FOR(a, b) for(int i = (a); i <= (b); i++)
#define FORr(a, b) for(int i = (a); i >= (b); i--)
#define sz(x) (int)(x).size()

#define YES cout << "YES\n"
#define NO cout << "NO\n"

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int rangerng(int l, int r){
    return uniform_int_distribution<>(l, r)(rng);
}

////////////////////////////////////////////////////////////////////////////////////

const int NMAX = 150000;

struct obj{
    int x, y, z;
}v[NMAX + 1];

map <pii, set <int>> llo, lol, oll;
multiset <int> fx, fy, fz;

void del(int ind){
    fx.erase(fx.find(v[ind].x));
    fy.erase(fy.find(v[ind].y));
    fz.erase(fz.find(v[ind].z));

    llo[{v[ind].x, v[ind].y}].erase(ind);
    lol[{v[ind].x, v[ind].z}].erase(ind);
    oll[{v[ind].y, v[ind].z}].erase(ind);
}

void solve(){
    int n;
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> v[i].x >> v[i].y >> v[i].z;
        llo[{v[i].x, v[i].y}].insert(i);
        lol[{v[i].x, v[i].z}].insert(i);
        oll[{v[i].y, v[i].z}].insert(i);
        fx.insert(v[i].x);
        fy.insert(v[i].y);
        fz.insert(v[i].z);       
    } 

    while(true){
        bool found = 0;
        int maxX, maxY, maxZ;

        if(fx.empty()){
            break;
        }

        maxX = (*fx.rbegin());
        maxY = (*fy.rbegin());

        for(int ind : llo[{maxX, maxY}]){
            found = 1;
            del(ind);
        }

        if(fx.empty()){
            break;
        }

        maxX = (*fx.rbegin());
        maxZ = (*fz.rbegin());

        for(int ind : lol[{maxX, maxZ}]){
            found = 1;
            del(ind);
        }

        if(fx.empty()){
            break;
        }

        maxY = (*fy.rbegin());
        maxZ = (*fz.rbegin());

        for(int ind : oll[{maxY, maxZ}]){
            found = 1;
            del(ind);
        }

        if(!found){
            break;
        }
    }

    if(sz(fx) < 3){
        cout << -1 << '\n';
        return;
    }

    int sum = (*fx.rbegin()) + (*fy.rbegin()) + (*fz.rbegin());
    cout << sum << '\n';
}           

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int T;
    //cin >> T;

    T = 1;

    while(T--){
        solve();
    }

    return 0;
}

/*
4
1 2 3
1 2 3
1 2 3
1 2 3
*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -