# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
106984 | someone_aa | Palembang Bridges (APIO15_bridge) | C++17 | 2056 ms | 3812 KiB |
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>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
ll s[maxn], f[maxn], n, k;
char szone[maxn], fzone[maxn];
int main() {
cin>>k>>n;
ll result = 0LL;
vector<ll>v;
for(int i=1;i<=n;i++) {
cin>>szone[i]>>s[i];
cin>>fzone[i]>>f[i];
if(szone[i] == fzone[i]) result += abs(f[i] - s[i]);
v.pb(s[i]);
v.pb(f[i]);
}
if(k == 1) {
ll mintemp = LLONG_MAX;
for(int i:v) {
ll temp = 0LL;
for(int j=1;j<=n;j++) {
if(szone[j] != fzone[j]) {
temp += abs(s[j] - i) + abs(f[j] - i) + 1;
}
}
mintemp = min(mintemp, temp);
//cout<<i<<": "<<temp<<"\n";
}
result += mintemp;
cout<<result<<"\n";
return 0;
}
else if(k == 2) {
ll mintemp = LLONG_MAX;
for(int i=0;i<v.size();i++) {
for(int j=i+1;j<v.size();j++) {
ll temp = 0LL;
for(int d=1;d<=n;d++) {
if(szone[d] != fzone[d]) {
temp += min(abs(f[d] - v[i]) + abs(s[d] - v[i]), abs(f[d] - v[j]) + abs(s[d] - v[j])) + 1LL;
}
}
mintemp = min(mintemp, temp);
}
}
result += mintemp;
cout<<result<<"\n";
return 0;
}
return 0;
}
Compilation message (stderr)
# | 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... |