# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
119451 | Charis02 | Palembang Bridges (APIO15_bridge) | C++14 | 3 ms | 512 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<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<utility>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 100004
#define INF 1e16
using namespace std;
ll n,k;
pi ar[N];
ll b,d;
char a,c;
ll ans,cnt;
map < ll,ll > telionei;
map < ll,ll > arxizei;
int main()
{
ios_base::sync_with_stdio(false);
cin >> k >> n;
rep(i,0,n)
{
cin >> a >> b >> c >> d;
if(d < b)
swap(b,d);
ans += d-b;
if(a != c)
{
ar[cnt].first = b;
arxizei[b]++;
ar[cnt].second = d;
telionei[d]++;
ans++;
cnt++;
}
}
set < ll > p;
rep(i,0,cnt)
{
p.insert(ar[i].first);
p.insert(ar[i].second);
}
vector < ll > possible;
for(set < ll >::iterator it = p.begin();it != p.end();it++)
{
possible.push_back(*it);
}
ll fin = INF;
ll aristera = 0;
ll bridge = possible[0];
ll res = ans;
ll deksia = 0;
rep(i,0,cnt)
{
if(ar[i].first <= bridge && bridge <= ar[i].second)
continue;
else if(bridge < ar[i].first)
{
deksia++;
res += 2*(ar[i].first - bridge);
}
else
{
aristera++;
res += 2*(bridge-ar[i].second);
}
}
fin = res;
rep(i,1,possible.size())
{
res += 2*aristera*(possible[i] - possible[i-1]);
res -= 2*deksia*(possible[i] - possible[i-1]);
bridge = possible[i];
/* if(telionei[bridge] != NULL)
aristera += telionei[bridge];
if(arxizei[bridge] != NULL)
deksia -= arxizei[bridge];
*/
fin = min(fin,res);
}
cout << fin;
return 0;
}
/*
1 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... |