이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long unPuente(vector<long long int> & S, vector<long long int> & T) {
int N = (int) S.size();
if (N == 0) return 0;
vector<long long 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());
long long int posicionPuente = (posiciones[N - 1] + posiciones[N])/2;
long long int total = (long long int) N;
for (int i = 0; i < N; i++) {
total += abs(S[i] - posicionPuente) + abs(T[i] - posicionPuente);
}
return total;
}
long long int dosPuentes(vector<long long int> & S, vector<long long int> & T) {
return 0;
}
int main() {
int K, N;
cin >> K >> N;
vector<long long int> S, T;
long long int mismoLado = 0;
for (int i = 0; i < N; i++) {
char lado1, lado2;
long long 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |