제출 #637939

#제출 시각아이디문제언어결과실행 시간메모리
637939BlancaHMPalembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms212 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int unPuente(vector<int> & S, vector<int> & T) {
    int N = (int) S.size();
    if (N == 0) return 0;
    vector<int> posiciones(2*N);
    for (int i = 0; i < N; i++) {
        posiciones[2*i] = S[i];
        posiciones[2*i+1] = T[i];
    }
    sort(posiciones.begin(), posiciones.end());
    int posicionPuente = (posiciones[N - 1] + posiciones[N])/2;
    int total = N;
    for (int i = 0; i < N; i++) {
        total += abs(S[i] - posicionPuente) + abs(T[i] - posicionPuente);
    }
    return total;
}

int dosPuentes(vector<int> & S, vector<int> & T) {
    return 0;
}

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> S, T;
    int mismoLado = 0;
    for (int i = 0; i < N; i++) {
        char lado1, lado2;
        int pos1, pos2;
        cin >> lado1 >> pos1 >> lado2 >> pos2;
        if (lado1 == lado2) {
            mismoLado += abs(pos1-pos2);
        } else {
            S.push_back(pos1);
            T.push_back(pos2);
        }
    }
    if (K == 1) {
        cout << mismoLado + unPuente(S, T) << '\n';
    } else {
        cout << mismoLado + dosPuentes(S, T) << '\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...