답안 #815714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815714 2023-08-08T19:48:52 Z Ozy 새 집 (APIO18_new_home) C++17
0 / 100
153 ms 30216 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a <<  " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli> 

#define MAX_k 400
#define MAX 60000
#define INF (1ll<<60)
#define LIM 10000000000
//para el vector de orden
#define pos first
#define tipo second.first 
#define id second.second 

lli n,q,k,a,b,c,d;
vector<pair<lli,pll>> orden;
multiset<lli> activos[MAX_k+2];
lli res[MAX];

void solve() {
    //inicializa
    lli last[MAX+2];
    set<pll> activos;
    rep(i,1,n) {
        last[i] = -INF;
        activos.insert({-INF, i});
    }

    for (auto act : orden) {
        
        if(act.tipo == 0) {
            activos.erase({last[act.id],act.id});
            last[act.id] = act.pos;
            activos.insert({last[act.id],act.id});
        }
        else {
            lli op = (*activos.begin()).first;
            lli mejor = abs( abs(op) - abs(act.pos) ); 
            res[act.id] = min(res[act.id],mejor);
        }

    }
}

//solucion de s3
int main() {

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

    cin >> n >> k >> q;
    rep(i,1,n) {
        cin >> a >> b >> c >> d;
        orden.push_back({a,{0,b}});
    }    
    rep(i,1,q) {
        cin >> a >> b;
        orden.push_back({a,{1,i}});
    }

    rep(i,1,q) res[i] = INF;
    
    sort(orden.begin(),orden.end());
    solve();
    reverse(orden.begin(), orden.end());
    for(auto &act : orden) act.pos *= (-1);
    solve();

    rep(i,1,q) if (res[i] > LIM) cout << "-1\n"; 
    else cout << res[i] << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 153 ms 30200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 145 ms 30216 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -