| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 914953 | 12345678 | Palembang Bridges (APIO15_bridge) | C++17 | 33 ms | 5592 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;
const int nx=1e5+5;
#define ll long long
ll k, n, b, d, cnt;
char a, c;
vector<ll> v, l;
vector<pair<ll, ll>> p(nx);
ll res, ans=LLONG_MAX;
ll cal(int b1, int b2)
{
ll tmp=0;
for (int i=0; i<cnt; i++) tmp+=min(abs(p[i].first-b1)+abs(p[i].second-b1), abs(p[i].first-b2)+abs(p[i].second-b2))+1; //cout<<"here "<<p[i].first<<' '<<p[i].second<<' '<<tmp<<'\n';
return tmp;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>k>>n;
if (k==1)
{
for (int i=0; i<n; i++)
{
cin>>a>>b>>c>>d;
if (a==c)
{
res+=abs(b-d);
continue;
}
v.push_back(b);
v.push_back(d);
res++;
}
sort(v.begin(), v.end());
int md=v[v.size()/2];
for (auto x:v) res+=abs(x-md);
cout<<res;
}
else
{
for (int i=0; i<n; i++)
{
cin>>a>>b>>c>>d;
if (a==c) res+=abs(b-d);
else p[cnt++]={b, d}, l.push_back(b), l.push_back(d);
}
for (int i=0; i<l.size(); i++) for (int j=i+1; j<l.size(); j++) ans=min(ans, res+cal(l[i], l[j])); //cout<<res<<' '<<l[i]<<' '<<l[j]<<' '<<cal(l[i], l[j])<<'\n';
cout<<ans;
}
}
/*
2 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
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... | ||||
