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;
// Idee 1 -> Set mit Wert|Index pair
// Idee 2 -> SegTree damit
struct Platz{
char type;
int c;
};
void solve(){
int k; cin >> k;
int n; cin >> n;
vector<Platz> home(n);
vector<Platz> arbeit(n);
set<int> coords;
for(int i = 0;i<n;i++){
cin >> home[i].type >> home[i].c >> arbeit[i].type >> arbeit[i].c;
coords.insert(home[i].c);
coords.insert(arbeit[i].c);
}
long long ans = 1e18;
for(set<int>::iterator it = coords.begin();it!=coords.end();it++){
for(set<int>::iterator it2 = it;it2 !=coords.end();it2++){
long long sum = 0;
for(int j = 0;j<n;j++){
if(home[j].type == arbeit[j].type){
sum += abs(home[j].c-arbeit[j].c);
}else{
sum += min(abs(home[j].c-*it)+abs(arbeit[j].c - *it),
abs(home[j].c-*it2) + abs(arbeit[j].c - *it2))+1;
}
}
ans = min(ans,sum);
}
}
cout << ans;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
cout << fixed << setprecision(8);
solve();
}
# | 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... |