# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
954545 | hihihihaw | Palembang Bridges (APIO15_bridge) | C++17 | 33 ms | 4332 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.
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define sz(v) (int)v.size()
#define fi first
#define se second
#define INF 1223372036854775807
#define MOD 1000000007
#define cint(x) int x;cin>>x;
#define cinarr(a,n) int a[n];for (int i=0;i<n;i++) cin>>a[i];
#define coutarr(a) for (auto d:a) cout<<d<<" "; cout<<endl;
#define coutarrD(a) for (auto d:a) cout<<d.fi<<","<<d.se<<" "; cout<<endl;
#define AYBERK_SARICA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define ld long double
int t=1;
int usaco=0;
vector<pii> v;
int f(int x){
int ans=0;
for (auto d:v)ans+=abs(x-d.fi)+abs(x-d.se)+1;
return ans;
}
void solve(){
int k,n;
cin>>k>>n;
int ans=0;
while (n--){
char a,b;
int x,y;
cin>>a>>x>>b>>y;
if (a==b) ans+=abs(x-y);
else{
v.pb({x,y});
}
}
int l=0,r=9999999999;
while (r>=l){
int m=(l+r)/2;
if (f(m)<=f(m+1)) r=m-1;
else l=m+1;
}
cout<<f(l)+ans<<endl;
}
int32_t main(){
AYBERK_SARICA;
if (usaco){
freopen("hayfeast.in", "r", stdin);
freopen("hayfeast.out", "w", stdout);
}
#ifdef Local
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
//freopen("wormsort.out", "w", stdout);
#endif
if (t==1) solve();
else{
cin>>t;
while (t--) solve();
}
return 0;
}
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... |