이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main () {
int k, n;
cin >> k >> n;
char ai, ci;
int bi, di;
long long o = 0;
vector< pair<int, int> > pts;
vector<int> vals;
for (int i=0; i<n; i++) {
cin >> ai >> bi >> ci >> di;
if (ai != ci) {
vals.push_back(bi);
vals.push_back(di);
pts.push_back(make_pair(min(bi, di), max(bi, di)));
} else {
o += abs(bi-di);
}
}
o += pts.size();
sort(vals.begin(), vals.end());
if (k == 1) {
int mid = vals[vals.size()/2];
for (auto i: vals) {
o += abs(mid-i);
}
cout << o << endl;
return 0;
}
vals.resize(unique(vals.begin(), vals.end())-vals.begin());
long long best = 1e15;
long long score = 0;
for (auto i: vals) {
for (auto j: vals) {
score = 0;
for (auto k: pts) {
score += min(abs(k.first-i)+abs(k.second-i), abs(k.first-j)+abs(k.second-j));
}
best = min(best, score);
}
}
o += best;
cout << o << endl;
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... |