This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int k, n, mn = LONG_LONG_MAX, sm;
cin >> k >> n;
set<int> st;
vector<pair<pair<char, int>, pair<char, int>>> vec(n);
for (int i = 0; i < n; ++i) {
cin >> vec[i].first.first >> vec[i].first.second >> vec[i].second.first >> vec[i].second.second;
st.insert(vec[i].first.second);
st.insert(vec[i].second.second);
}
if (k == 1) {
for (int i: st) {
sm = 0;
for (int j = 0; j < n; ++j) {
if (vec[j].first.first == vec[j].second.first) sm += abs(vec[j].first.second - vec[j].second.second);
else sm += abs(i - vec[j].second.second) + abs(vec[j].first.second - i) + 1;
}
mn = min(sm, mn);
}
}
else {
for (int i : st) {
for (int l : st) {
sm = 0;
for (int j = 0; j < n; ++j) {
if (vec[j].first.first == vec[j].second.first) sm += abs(vec[j].first.second - vec[j].second.second);
else sm += min(abs(i - vec[j].second.second) + abs(vec[j].first.second - i) + 1, abs(l - vec[j].second.second) + abs(vec[j].first.second - l) + 1);
}
mn = min(sm, mn);
}
}
}
cout << mn;
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... |