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 fi first
#define se second
#define pb push_back
using namespace std;
int k,n;ll re=0;
map<ll,int>st,en;
ll no=0,fin=0;vector<pair<ll,ll>>v;
int main()
{
cin>>k>>n;ll w=0;
for(int i=0;i<n;i++)
{
char a,b;
int x,y;
cin>>a>>x>>b>>y;
re+=abs(x-y);
if(a==b)continue;
re++;
if(x>y)swap(x,y);
v.pb({x,y});
st[x]++;st[x+1];st[x-1];st[y+1];st[y-1];
st[y];no++;
en[y]++;w+=x;
}
ll mn=1e17;
ll last=0;
for(auto it:st)
{if(it.fi<0)continue;
ll z=0;
for(auto ff:v)
{
if(ff.fi<=it.fi&&ff.se>=it.fi)continue;
ll u=min(abs(ff.fi-it.fi),abs(ff.se-it.fi));
u*=2;
z+=u;
}
mn=min(mn,z);
/*
w+=fin*(it.fi-last);
w-=no*(it.fi-last);
fin+=en[it.fi];
no-=st[it.fi];
mn=min(mn,w);last=it.fi;
*/}
re+=mn;
cout<<re;
}
Compilation message (stderr)
bridge.cpp: In function 'int main()':
bridge.cpp:28:8: warning: unused variable 'last' [-Wunused-variable]
28 | ll last=0;
| ^~~~
# | 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... |