# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
637928 | Iwanttobreakfree | Palembang Bridges (APIO15_bridge) | C++17 | 105 ms | 7080 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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
signed main(){
int n,k;
cin>>k>>n;
char a,b;
int x,y,ans=0;
if(k==1){
int sum=0;
vector<int> cnt(n);
vector<pair<int,int>> events;
for(int i=0;i<n;i++){
cin>>a>>x>>b>>y;
if(a==b){
ans+=abs(y-x);
continue;
}
events.push_back({x,i});
events.push_back({y,i});
sum+=x+y;
}
sort(events.begin(),events.end());
int r=events.size()/2,l=0;
int cur=ans+sum+r,last=0;
//cout<<sum<<'\n';
ans=cur;
for(int i=0;i<events.size();i++){
int u=events[i].first,p=events[i].second;
cnt[p]++;
cur-=(u-last)*2*r;
cur+=(u-last)*2*l;
ans=min(ans,cur);
if(cnt[p]==2)l++;
else r--;
last=u;
//cout<<cur<<'\n';
}
cout<<ans<<'\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... |