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);
for(int i = 0;i<n;i++){
cin >> home[i].type >> home[i].c >> arbeit[i].type >> arbeit[i].c;
}
long long ans = 1e9;
for(int i = 0;i<n;i++){
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 += abs(home[j].c-home[i].c) + abs(arbeit[j].c - home[i].c)+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... |