# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549877 | ala2 | Palembang Bridges (APIO15_bridge) | C++14 | 1 ms | 300 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 int long long
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
using namespace std;
vector<pair<int,int>>v;
int f(int x)
{
int g=0;
for(int i=0;i<v.size();i++)
{
g+=abs(v[i].F-x )+abs(v[i].S-x);
}
return g;
}
signed main()
{
int n,k;
cin>>k>>n;
int ans=0;
for(int i=0;i<n;i++)
{
char x,y;
int a,b;
cin>>x>>a>>y>>b;
if(x==y)
{
ans+=abs(a-b);
}
else v.pb({a,b}),ans++;
}
int mn=1e18;
for(int i=0;i<v.size();i++)
{
mn=min(mn,f(v[i].F));
}
cout<<mn+ans<<endl;
}
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... |