# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
766389 | ivopav | Palembang Bridges (APIO15_bridge) | C++17 | 1 ms | 212 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>
using namespace std;
int main(){
int n;
int k;
cin >> k >> n;
int isp=0;
vector<pair<int,int>> lis={};
for (int i=0;i<n;i++){
char prvgdje;
int prv;
char drugdje;
int dru;
cin >> prvgdje >> prv >> drugdje >> dru;
if (prvgdje==drugdje){
isp+=abs(prv-dru);
}
else {
lis.push_back({prv,dru});
}
}
int poc=0;
int kra=1000000001;
int sre=kra/2;
while (poc<sre){
int zbr1=0;
int zbr2=0;
for (int i=0;i<lis.size();i++){
zbr1+=abs(sre-lis[i].first)+abs(sre-lis[i].second);
zbr2+=abs(sre+1-lis[i].first)+abs(sre+1-lis[i].second);
}
if (zbr1==zbr2){
break;
}
else if (zbr1<zbr2){
kra=sre;
}
else {
poc=sre;
}
sre=(poc+kra)/2;
}
int zbr1=0;
int zbr2=0;
int zbr3=0;
for (int i=0;i<lis.size();i++){
zbr1+=abs((sre-1)-lis[i].first)+abs((sre-1)-lis[i].second);
zbr2+=abs((sre)-lis[i].first)+abs((sre)-lis[i].second);
zbr3+=abs((sre+1)-lis[i].first)+abs((sre+1)-lis[i].second);
}
// cout << isp << " " << sre << " " << zbr1 << " " << zbr2 << " " << zbr3 << "\n";
cout << isp+min(zbr1,min(zbr2,zbr3))+lis.size() << "\n";
}
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... |